本文整理汇总了Python中pyroute2.IPRoute.neigh方法的典型用法代码示例。如果您正苦于以下问题:Python IPRoute.neigh方法的具体用法?Python IPRoute.neigh怎么用?Python IPRoute.neigh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyroute2.IPRoute
的用法示例。
在下文中一共展示了IPRoute.neigh方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestIPRoute
# 需要导入模块: from pyroute2 import IPRoute [as 别名]
# 或者: from pyroute2.IPRoute import neigh [as 别名]
#.........这里部分代码省略.........
name = uifname()
self.ip.link_create(ifname=name, kind=kind)
devs = self.ip.link_lookup(ifname=name)
assert devs
self.ifaces.extend(devs)
def test_create_dummy(self):
require_user('root')
self._create('dummy')
def test_create_bond(self):
require_user('root')
self._create('bond')
def test_create_bridge(self):
require_user('root')
self._create('bridge')
def test_create_ovs_bridge(self):
require_user('root')
self._create('ovs-bridge')
def test_create_team(self):
require_user('root')
self._create('team')
def test_ntables(self):
setA = set(filter(lambda x: x is not None,
[x.get_attr('NDTA_PARMS').get_attr('NDTPA_IFINDEX')
for x in self.ip.get_ntables()]))
setB = set([x['index'] for x in self.ip.get_links()])
assert setA == setB
def test_neigh_real_links(self):
links = set([x['index'] for x in self.ip.get_links()])
neigh = set([x['ifindex'] for x in self.ip.get_neighbours()])
assert neigh < links
def test_neigh_filter(self):
require_user('root')
# inject arp records
self.ip.neigh('add',
dst='172.16.45.1',
lladdr='00:11:22:33:44:55',
ifindex=self.ifaces[0])
self.ip.neigh('add',
dst='172.16.45.2',
lladdr='00:11:22:33:44:55',
ifindex=self.ifaces[0])
# assert two arp records on the interface
assert len(self.ip.get_neighbours(ifindex=self.ifaces[0])) == 2
# filter by dst
assert len(self.ip.get_neighbours(dst='172.16.45.1')) == 1
# filter with lambda
assert len(self.ip.get_neighbours(match=lambda x: x['ifindex'] ==
self.ifaces[0])) == 2
def test_mass_ipv6(self):
#
# Achtung! This test is time consuming.
# It is really time consuming, I'm not not
# kidding you. Beware.
#
require_user('root')
base = 'fdb3:84e5:4ff4:55e4::{0}'
limit = int(os.environ.get('PYROUTE2_SLIMIT', '0x800'), 16)
示例2: TestIPRoute
# 需要导入模块: from pyroute2 import IPRoute [as 别名]
# 或者: from pyroute2.IPRoute import neigh [as 别名]
#.........这里部分代码省略.........
r = self.ip.fdb('dump', ifindex=vx, lladdr=l2)
assert len(r) == 1
assert r[0]['ifindex'] == vx
assert r[0].get_attr('NDA_LLADDR') == l2
assert r[0].get_attr('NDA_DST') == ifaddr
assert r[0].get_attr('NDA_PORT') == 5678
assert r[0].get_attr('NDA_VNI') == 600
def test_fdb_bridge_simple(self):
require_kernel(4, 4)
require_user('root')
require_kernel(4, 4)
# create bridge
(bn, bx) = self._create('bridge')
# create FDB record
l2 = '00:11:22:33:44:55'
self.ip.fdb('add', lladdr=l2, ifindex=bx)
# dump FDB
r = self.ip.fdb('dump', ifindex=bx, lladdr=l2)
# one vlan == 1, one w/o vlan
assert len(r) == 2
assert len(list(filter(lambda x: x['ifindex'] == bx, r))) == 2
assert len(list(filter(lambda x: x.get_attr('NDA_VLAN'), r))) == 1
assert len(list(filter(lambda x: x.get_attr('NDA_MASTER') == bx,
r))) == 2
assert len(list(filter(lambda x: x.get_attr('NDA_LLADDR') == l2,
r))) == 2
r = self.ip.fdb('dump', ifindex=bx, lladdr=l2, vlan=1)
assert len(r) == 1
assert r[0].get_attr('NDA_VLAN') == 1
assert r[0].get_attr('NDA_MASTER') == bx
assert r[0].get_attr('NDA_LLADDR') == l2
def test_neigh_real_links(self):
links = set([x['index'] for x in self.ip.get_links()])
neigh = set([x['ifindex'] for x in self.ip.get_neighbours()])
assert neigh < links
def test_neigh_filter(self):
require_user('root')
ifaddr1 = self.ifaddr(1)
ifaddr2 = self.ifaddr(1)
# inject arp records
self.ip.neigh('add',
dst=ifaddr1,
lladdr='00:11:22:33:44:55',
ifindex=self.ifaces[0])
self.ip.neigh('add',
dst=ifaddr2,
lladdr='00:11:22:33:44:55',
ifindex=self.ifaces[0])
# assert two arp records on the interface
assert len(self.ip.get_neighbours(ifindex=self.ifaces[0])) == 2
# filter by dst
assert len(self.ip.get_neighbours(dst=ifaddr1)) == 1
# filter with lambda
assert len(self.ip.get_neighbours(match=lambda x: x['ifindex'] ==
self.ifaces[0])) == 2
def test_mass_ipv6(self):
#
# Achtung! This test is time consuming.
# It is really time consuming, I'm not not
# kidding you. Beware.
#
require_user('root')
示例3: TestIPRoute
# 需要导入模块: from pyroute2 import IPRoute [as 别名]
# 或者: from pyroute2.IPRoute import neigh [as 别名]
#.........这里部分代码省略.........
# dump
r = self.ip.fdb('dump', ifindex=vx, lladdr=l2)
assert len(r) == 1
assert r[0]['ifindex'] == vx
assert r[0].get_attr('NDA_LLADDR') == l2
assert r[0].get_attr('NDA_DST') == '172.16.40.40'
assert r[0].get_attr('NDA_PORT') == 5678
assert r[0].get_attr('NDA_VNI') == 600
def test_fdb_bridge_simple(self):
require_kernel(4, 4)
require_user('root')
# create bridge
(bn, bx) = self._create('bridge')
# create FDB record
l2 = '00:11:22:33:44:55'
self.ip.fdb('add', lladdr=l2, ifindex=bx)
# dump FDB
r = self.ip.fdb('dump', ifindex=bx, lladdr=l2)
# one vlan == 1, one w/o vlan
assert len(r) == 2
assert len(list(filter(lambda x: x['ifindex'] == bx, r))) == 2
assert len(list(filter(lambda x: x.get_attr('NDA_VLAN'), r))) == 1
assert len(list(filter(lambda x: x.get_attr('NDA_MASTER') == bx,
r))) == 2
assert len(list(filter(lambda x: x.get_attr('NDA_LLADDR') == l2,
r))) == 2
r = self.ip.fdb('dump', ifindex=bx, lladdr=l2, vlan=1)
assert len(r) == 1
assert r[0].get_attr('NDA_VLAN') == 1
assert r[0].get_attr('NDA_MASTER') == bx
assert r[0].get_attr('NDA_LLADDR') == l2
def test_neigh_real_links(self):
links = set([x['index'] for x in self.ip.get_links()])
neigh = set([x['ifindex'] for x in self.ip.get_neighbours()])
assert neigh < links
def test_neigh_filter(self):
require_user('root')
# inject arp records
self.ip.neigh('add',
dst='172.16.45.1',
lladdr='00:11:22:33:44:55',
ifindex=self.ifaces[0])
self.ip.neigh('add',
dst='172.16.45.2',
lladdr='00:11:22:33:44:55',
ifindex=self.ifaces[0])
# assert two arp records on the interface
assert len(self.ip.get_neighbours(ifindex=self.ifaces[0])) == 2
# filter by dst
assert len(self.ip.get_neighbours(dst='172.16.45.1')) == 1
# filter with lambda
assert len(self.ip.get_neighbours(match=lambda x: x['ifindex'] ==
self.ifaces[0])) == 2
def test_mass_ipv6(self):
#
# Achtung! This test is time consuming.
# It is really time consuming, I'm not not
# kidding you. Beware.
#
require_user('root')
base = 'fdb3:84e5:4ff4:55e4::{0}'
limit = int(os.environ.get('PYROUTE2_SLIMIT', '0x800'), 16)