encode.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:nfvOrchestrator 作者: uestcNFVproject 项目源码 文件源码
def process_context_headers(ctx1=0, ctx2=0, ctx3=0, ctx4=0):
    """
    Encode context header values in NSH header. The function
    is smart enough that is one of the values is an IP address
    it will properly convert to a integer and encode it properly
    :param ctx1: NSH context header 1
    :param ctx2: NSH context header 2
    :param ctx3: NSH context header 3
    :param ctx4: NSH context header 4
    :return: Array of encoded headers
    """
    context_headers = []
    for ctx in [ctx1, ctx2, ctx3, ctx4]:
        try:
            ipaddr = ipaddress.IPv4Address(ctx)
            context_headers.append(int(ipaddr))
        except ValueError:
            try:
                context_headers.append((int(ctx) & 0xFFFFFFFF))
            except ValueError:
                logger.error("Context header %d can not be represented as an integer", ctx)

    return context_headers
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号