当前位置: 首页>>代码示例>>Python>>正文


Python IPRoute.brport方法代码示例

本文整理汇总了Python中pyroute2.IPRoute.brport方法的典型用法代码示例。如果您正苦于以下问题:Python IPRoute.brport方法的具体用法?Python IPRoute.brport怎么用?Python IPRoute.brport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyroute2.IPRoute的用法示例。


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

示例1: TestIPRoute

# 需要导入模块: from pyroute2 import IPRoute [as 别名]
# 或者: from pyroute2.IPRoute import brport [as 别名]

#.........这里部分代码省略.........
                    .get_attr('IFLA_IFNAME')) == name
            assert (self
                    .ip
                    .get_vlans(ifname=name)[0]
                    .get_nested('IFLA_AF_SPEC',
                                'IFLA_BRIDGE_VLAN_INFO'))['vid'] == 1

    def test_vlan_filter_add(self):
        require_user('root')
        (bn, bx) = self.create('bridge')
        (sn, sx) = self.create('dummy')
        self.ip.link('set', index=sx, master=bx)
        assert not grep('bridge vlan show', pattern=' 568')
        self.ip.vlan_filter('add', index=sx, vlan_info={'vid': 568})
        assert grep('bridge vlan show', pattern=' 568')
        self.ip.vlan_filter('del', index=sx, vlan_info={'vid': 568})
        assert not grep('bridge vlan show', pattern=' 568')

    def test_vlan_filter_add_raw(self):
        require_user('root')
        (bn, bx) = self.create('bridge')
        (sn, sx) = self.create('dummy')
        self.ip.link('set', index=sx, master=bx)
        assert not grep('bridge vlan show', pattern=' 567')
        self.ip.vlan_filter('add', index=sx,
                            af_spec={'attrs': [['IFLA_BRIDGE_VLAN_INFO',
                                                {'vid': 567}]]})
        assert grep('bridge vlan show', pattern=' 567')
        self.ip.vlan_filter('del', index=sx,
                            af_spec={'attrs': [['IFLA_BRIDGE_VLAN_INFO',
                                                {'vid': 567}]]})
        assert not grep('bridge vlan show', pattern=' 567')

    def test_brport_basic(self):
        require_user('root')
        (bn, bx) = self.create('bridge')
        (sn, sx) = self.create('dummy')
        self.ip.link('set', index=sx, master=bx)
        self.ip.link('set', index=sx, state='up')
        self.ip.link('set', index=bx, state='up')

        self.ip.brport('set',
                       index=sx,
                       unicast_flood=0,
                       cost=200,
                       proxyarp=1)

        port = self.ip.brport('show', index=sx)[0]
        protinfo = port.get_attr('IFLA_PROTINFO')
        assert protinfo.get_attr('IFLA_BRPORT_COST') == 200
        assert protinfo.get_attr('IFLA_BRPORT_PROXYARP') == 1
        assert protinfo.get_attr('IFLA_BRPORT_UNICAST_FLOOD') == 0

    def test_local_add(self):
        require_user('root')
        ifaddr1 = self.ifaddr()
        ifaddr2 = self.ifaddr()
        self.ip.addr('add', self.ifaces[0],
                     address=ifaddr1,
                     local=ifaddr2,
                     mask=24)
        link = self.ip.get_addr(index=self.ifaces[0])[0]
        address = link.get_attr('IFA_ADDRESS')
        local = link.get_attr('IFA_LOCAL')
        assert address == ifaddr1
        assert local == ifaddr2
开发者ID:svinota,项目名称:pyroute2,代码行数:70,代码来源:test_ipr.py


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