• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python nla.encode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyroute2.netlink.nla.encode函数的典型用法代码示例。如果您正苦于以下问题:Python encode函数的具体用法?Python encode怎么用?Python encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了encode函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: encode

 def encode(self):
     r_prio = struct.pack('H', self['prio'])
     r_addr = struct.pack('BBBBBB',
                          *[int(i, 16) for i in
                            self['addr'].split(':')])
     self['value'] = r_prio + r_addr
     nla.encode(self)
开发者ID:bschlinker,项目名称:pyroute2,代码行数:7,代码来源:ifinfmsg.py


示例2: encode

 def encode(self):
     family = self.get('family', AF_UNSPEC)
     if family in (AF_INET, AF_INET6):
         addr = inet_pton(family, self['addr'])
     else:
         raise TypeError('Family %s not supported for RTA_VIA'
                         % family)
     self['value'] = struct.pack('H', family) + addr
     nla.encode(self)
开发者ID:kinhvan017,项目名称:pyroute2,代码行数:9,代码来源:rtmsg.py


示例3: encode

 def encode(self):
     parms = self.parent.get_encoded('TCA_TBF_PARMS') or \
         self.parent.get_encoded('TCA_HTB_PARMS') or \
         self.parent.get_encoded('TCA_POLICE_TBF')
     if parms is not None:
         self.value = getattr(parms, self.__class__.__name__)
         self['value'] = struct.pack('I' * 256,
                                     *(int(x) for x in self.value))
     nla.encode(self)
开发者ID:FirefighterBlu3,项目名称:pyroute2,代码行数:9,代码来源:tcmsg.py


示例4: encode

 def encode(self):
     # Get action type and convert string to value
     action = self['value']
     self['value'] = (self
                      .actions
                      .get(action,
                           self.SEG6_LOCAL_ACTION_UNSPEC))
     # Convert action type to u32
     self['value'] = self['value'] & 0xffffffff
     # Finally encode as nla
     nla.encode(self)
开发者ID:celebdor,项目名称:pyroute2,代码行数:11,代码来源:rtmsg.py


示例5: encode

                def encode(self):
                    #
                    # for details see:
                    url = 'https://github.com/svinota/pyroute2/issues/531'

                    v = self.value
                    for flag in GRE_VALUES:
                        v &= ~flag
                    if v != 0:
                        log.warning('possibly incorrect GRE flags, '
                                    'see %s' % url)
                    nla.encode(self)
开发者ID:svinota,项目名称:pyroute2,代码行数:12,代码来源:__init__.py


示例6: encode

 def encode(self):
     family = self.get('family', AF_UNSPEC)
     if family in (AF_INET, AF_INET6):
         addr = inet_pton(family, self['addr'])
     self['value'] = struct.pack('H', family) + addr
     nla.encode(self)
开发者ID:FirefighterBlu3,项目名称:pyroute2,代码行数:6,代码来源:rtmsg.py


示例7: encode

 def encode(self):
     self['flow_keys'] = self['value']
     nla.encode(self)
开发者ID:celebdor,项目名称:pyroute2,代码行数:3,代码来源:cls_flow.py


示例8: encode

 def encode(self):
     self['value'] = struct.pack('B' * 256,
                                 *(int(x) for x in self.value))
     nla.encode(self)
开发者ID:0xD3ADB33F,项目名称:pyroute2,代码行数:4,代码来源:sched_choke.py


示例9: encode

        def encode(self):
            '''
            Key sample::

                'keys': ['0x0006/0x00ff+8',
                         '0x0000/0xffc0+2',
                         '0x5/0xf+0',
                         '0x10/0xff+33']

                => 00060000/00ff0000 + 8
                   05000000/0f00ffc0 + 0
                   00100000/00ff0000 + 32
            '''

            def cut_field(key, separator):
                '''
                split a field from the end of the string
                '''
                field = '0'
                pos = key.find(separator)
                new_key = key
                if pos > 0:
                    field = key[pos + 1:]
                    new_key = key[:pos]
                return (new_key, field)

            # 'header' array to pack keys to
            header = [(0, 0) for i in range(256)]

            keys = []
            # iterate keys and pack them to the 'header'
            for key in self['keys']:
                # TODO tags: filter
                (key, nh) = cut_field(key, '@')  # FIXME: do not ignore nh
                (key, offset) = cut_field(key, '+')
                offset = int(offset, 0)
                # a little trick: if you provide /00ff+8, that
                # really means /ff+9, so we should take it into
                # account
                (key, mask) = cut_field(key, '/')
                if mask[:2] == '0x':
                    mask = mask[2:]
                    while True:
                        if mask[:2] == '00':
                            offset += 1
                            mask = mask[2:]
                        else:
                            break
                    mask = '0x' + mask
                mask = int(mask, 0)
                value = int(key, 0)
                bits = 24
                if mask == 0 and value == 0:
                    key = self.u32_key(self.buf)
                    key['key_off'] = offset
                    key['key_mask'] = mask
                    key['key_val'] = value
                    keys.append(key)
                for bmask in struct.unpack('4B', struct.pack('>I', mask)):
                    if bmask > 0:
                        bvalue = (value & (bmask << bits)) >> bits
                        header[offset] = (bvalue, bmask)
                        offset += 1
                    bits -= 8

            # recalculate keys from 'header'
            key = None
            value = 0
            mask = 0
            for offset in range(256):
                (bvalue, bmask) = header[offset]
                if bmask > 0 and key is None:
                    key = self.u32_key(self.buf)
                    key['key_off'] = offset
                    key['key_mask'] = 0
                    key['key_val'] = 0
                    bits = 24
                if key is not None and bits >= 0:
                    key['key_mask'] |= bmask << bits
                    key['key_val'] |= bvalue << bits
                    bits -= 8
                    if (bits < 0 or offset == 255):
                        keys.append(key)
                        key = None

            assert keys
            self['nkeys'] = len(keys)
            # FIXME: do not hardcode flags :)
            self['flags'] = 1
            start = self.buf.tell()

            nla.encode(self)
            for key in keys:
                key.encode()
            self.update_length(start)
开发者ID:GateprotectGmbH,项目名称:pyroute2,代码行数:95,代码来源:cls_u32.py


示例10: encode

 def encode(self):
     # convert flags
     if isinstance(self['value'], basestring):
         self['value'] = BRIDGE_FLAGS_NAMES['BRIDGE_FLAGS_' +
                                            self['value'].upper()]
     nla.encode(self)
开发者ID:craneworks,项目名称:pyroute2,代码行数:6,代码来源:__init__.py


示例11: encode

 def encode(self):
     self["value"] = state_by_name[self.value]
     nla.encode(self)
开发者ID:kansifang,项目名称:ip-white-list-of-firewall,代码行数:3,代码来源:ifinfmsg.py


示例12: encode

 def encode(self):
     self['start'], self['end'] = self.value.split(':')
     nla.encode(self)
开发者ID:svinota,项目名称:pyroute2,代码行数:3,代码来源:fibmsg.py



注:本文中的pyroute2.netlink.nla.encode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python netns.remove函数代码示例发布时间:2022-05-27
下一篇:
Python nla.decode函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap