Exemple #1
0
 def test_lwtunnel_multipath_mpls(self):
     require_kernel(4, 4)
     require_user('root')
     require_kernel(4, 5)
     naddr = str(self.ipnets[1].network)
     self.ip.route('add',
                   dst='%s/24' % naddr,
                   multipath=[{'encap': {'type': 'mpls',
                                         'labels': 500},
                               'oif': 1},
                              {'encap': {'type': 'mpls',
                                         'labels': '600/700'},
                               'gateway': '127.0.0.4'}])
     routes = self.ip.route('dump', dst='%s/24' % naddr)
     assert len(routes) == 1
     mp = routes[0].get_attr('RTA_MULTIPATH')
     assert len(mp) == 2
     assert mp[0]['oif'] == 1
     assert mp[0].get_attr('RTA_ENCAP_TYPE') == 1
     labels = mp[0].get_attr('RTA_ENCAP').get_attr('MPLS_IPTUNNEL_DST')
     assert len(labels) == 1
     assert labels[0]['bos'] == 1
     assert labels[0]['label'] == 500
     assert mp[1].get_attr('RTA_ENCAP_TYPE') == 1
     labels = mp[1].get_attr('RTA_ENCAP').get_attr('MPLS_IPTUNNEL_DST')
     assert len(labels) == 2
     assert labels[0]['bos'] == 0
     assert labels[0]['label'] == 600
     assert labels[1]['bos'] == 1
     assert labels[1]['label'] == 700
     self.ip.route('del', dst='%s/24' % naddr)
Exemple #2
0
 def test_route_mpls_swap_newdst_list(self):
     require_kernel(4, 4)
     require_user('root')
     req = {'family': AF_MPLS,
            'oif': self.ifaces[0],
            'dst': {'label': 0x20,
                    'bos': 1},
            'newdst': [{'label': 0x21,
                        'bos': 1}]}
     self.ip.route('add', **req)
     rt = self.ip.get_routes(oif=self.ifaces[0], family=AF_MPLS)[0]
     assert rt.get_attr('RTA_DST')[0]['label'] == 0x20
     assert len(rt.get_attr('RTA_DST')) == 1
     assert rt.get_attr('RTA_NEWDST')[0]['label'] == 0x21
     assert len(rt.get_attr('RTA_NEWDST')) == 1
     self.ip.route('del', **req)
     assert len(self.ip.get_routes(oif=self.ifaces[0], family=AF_MPLS)) == 0
Exemple #3
0
 def test_lwtunnel_mpls_1_int_label(self):
     require_kernel(4, 4)
     require_user('root')
     self.ip.route('add',
                   dst='172.16.245.0/24',
                   encap={'type': 'mpls',
                          'labels': 245},
                   oif=1)
     routes = self.ip.route('dump', dst='172.16.245.0/24')
     assert len(routes) == 1
     route = routes[0]
     assert route.get_attr('RTA_ENCAP_TYPE') == 1
     assert route.get_attr('RTA_OIF') == 1
     labels = route.get_attr('RTA_ENCAP').get_attr('MPLS_IPTUNNEL_DST')
     assert len(labels) == 1
     assert labels[0]['bos'] == 1
     assert labels[0]['label'] == 245
     self.ip.route('del', dst='172.16.245.0/24')
Exemple #4
0
 def test_fdb_vxlan(self):
     require_kernel(4, 4)
     require_user('root')
     # create dummy
     (dn, dx) = self._create('dummy')
     # create vxlan on it
     (vn, vx) = self._create('vxlan', vxlan_link=dx, vxlan_id=500)
     # create FDB record
     l2 = '00:11:22:33:44:55'
     self.ip.fdb('add', lladdr=l2, ifindex=vx,
                 vni=600, port=5678, dst='172.16.40.40')
     # 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
Exemple #5
0
 def test_lwtunnel_mpls_1_str_label(self):
     require_kernel(4, 4)
     require_user('root')
     require_kernel(4, 3)
     naddr = str(self.ipnets[1].network)
     self.ip.route('add',
                   dst='%s/24' % naddr,
                   encap={'type': 'mpls',
                          'labels': "244"},
                   oif=1)
     routes = self.ip.route('dump', dst='%s/24' % naddr)
     assert len(routes) == 1
     route = routes[0]
     assert route.get_attr('RTA_ENCAP_TYPE') == 1
     assert route.get_attr('RTA_OIF') == 1
     labels = route.get_attr('RTA_ENCAP').get_attr('MPLS_IPTUNNEL_DST')
     assert len(labels) == 1
     assert labels[0]['bos'] == 1
     assert labels[0]['label'] == 244
     self.ip.route('del', dst='%s/24' % naddr)
Exemple #6
0
 def test_lwtunnel_mpls_dict_label(self):
     require_kernel(4, 4)
     require_user('root')
     self.ip.route('add',
                   dst='172.16.226.0/24',
                   encap={'type': 'mpls',
                          'labels': [{'bos': 0, 'label': 226},
                                     {'bos': 1, 'label': 227}]},
                   gateway='127.0.0.2')
     routes = self.ip.route('dump', dst='172.16.226.0/24')
     assert len(routes) == 1
     route = routes[0]
     assert route.get_attr('RTA_ENCAP_TYPE') == 1
     assert route.get_attr('RTA_GATEWAY') == '127.0.0.2'
     labels = route.get_attr('RTA_ENCAP').get_attr('MPLS_IPTUNNEL_DST')
     assert len(labels) == 2
     assert labels[0]['bos'] == 0
     assert labels[0]['label'] == 226
     assert labels[1]['bos'] == 1
     assert labels[1]['label'] == 227
     self.ip.route('del', dst='172.16.226.0/24')
Exemple #7
0
 def _test_route_mpls_via_ipv(self, family, address, label):
     require_kernel(4, 4)
     require_user('root')
     self.ip.route('add', **{'family': AF_MPLS,
                             'oif': self.ifaces[0],
                             'via': {'family': family,
                                     'addr': address},
                             'newdst': {'label': label,
                                        'bos': 1}})
     rt = self.ip.get_routes(oif=self.ifaces[0], family=AF_MPLS)[0]
     assert rt.get_attr('RTA_VIA')['addr'] == address
     assert rt.get_attr('RTA_VIA')['family'] == family
     assert rt.get_attr('RTA_NEWDST')[0]['label'] == label
     assert len(rt.get_attr('RTA_NEWDST')) == 1
     self.ip.route('del', **{'family': AF_MPLS,
                             'oif': self.ifaces[0],
                             'dst': {'label': 0x10,
                                     'bos': 1},
                             'via': {'family': family,
                                     'addr': address},
                             'newdst': {'label': label,
                                        'bos': 1}})
     assert len(self.ip.get_routes(oif=self.ifaces[0], family=AF_MPLS)) == 0
Exemple #8
0
 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
Exemple #9
0
 def test_route_mpls_swap_newdst_list(self):
     require_kernel(4, 4)
     require_user('root')
     req = {
         'family': AF_MPLS,
         'oif': self.ifaces[0],
         'dst': {
             'label': 0x20,
             'bos': 1
         },
         'newdst': [{
             'label': 0x21,
             'bos': 1
         }]
     }
     self.ip.route('add', **req)
     rt = self.ip.get_routes(oif=self.ifaces[0], family=AF_MPLS)[0]
     assert rt.get_attr('RTA_DST')[0]['label'] == 0x20
     assert len(rt.get_attr('RTA_DST')) == 1
     assert rt.get_attr('RTA_NEWDST')[0]['label'] == 0x21
     assert len(rt.get_attr('RTA_NEWDST')) == 1
     self.ip.route('del', **req)
     assert len(self.ip.get_routes(oif=self.ifaces[0], family=AF_MPLS)) == 0
Exemple #10
0
 def test_fdb_vxlan(self):
     require_kernel(4, 4)
     require_user('root')
     # create dummy
     (dn, dx) = self._create('dummy')
     # create vxlan on it
     (vn, vx) = self._create('vxlan', vxlan_link=dx, vxlan_id=500)
     # create FDB record
     l2 = '00:11:22:33:44:55'
     self.ip.fdb('add',
                 lladdr=l2,
                 ifindex=vx,
                 vni=600,
                 port=5678,
                 dst='172.16.40.40')
     # 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
Exemple #11
0
 def test_lwtunnel_multipath_mpls(self):
     require_kernel(4, 4)
     require_user('root')
     require_kernel(4, 5)
     self.ip.route('add',
                   dst='172.16.216.0/24',
                   multipath=[{
                       'encap': {
                           'type': 'mpls',
                           'labels': 500
                       },
                       'oif': 1
                   }, {
                       'encap': {
                           'type': 'mpls',
                           'labels': '600/700'
                       },
                       'gateway': '127.0.0.4'
                   }])
     routes = self.ip.route('dump', dst='172.16.216.0/24')
     assert len(routes) == 1
     mp = routes[0].get_attr('RTA_MULTIPATH')
     assert len(mp) == 2
     assert mp[0]['oif'] == 1
     assert mp[0].get_attr('RTA_ENCAP_TYPE') == 1
     labels = mp[0].get_attr('RTA_ENCAP').get_attr('MPLS_IPTUNNEL_DST')
     assert len(labels) == 1
     assert labels[0]['bos'] == 1
     assert labels[0]['label'] == 500
     assert mp[1].get_attr('RTA_ENCAP_TYPE') == 1
     labels = mp[1].get_attr('RTA_ENCAP').get_attr('MPLS_IPTUNNEL_DST')
     assert len(labels) == 2
     assert labels[0]['bos'] == 0
     assert labels[0]['label'] == 600
     assert labels[1]['bos'] == 1
     assert labels[1]['label'] == 700
     self.ip.route('del', dst='172.16.216.0/24')
Exemple #12
0
 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
Exemple #13
0
 def test_lwtunnel_mpls_2_int_label(self):
     require_kernel(4, 4)
     require_user('root')
     require_kernel(4, 3)
     naddr = str(self.ipnets[1].network)
     self.ip.route('add',
                   dst='%s/24' % naddr,
                   encap={
                       'type': 'mpls',
                       'labels': [206, 207]
                   },
                   oif=1)
     routes = self.ip.route('dump', dst='%s/24' % naddr)
     assert len(routes) == 1
     route = routes[0]
     assert route.get_attr('RTA_ENCAP_TYPE') == 1
     assert route.get_attr('RTA_OIF') == 1
     labels = route.get_attr('RTA_ENCAP').get_attr('MPLS_IPTUNNEL_DST')
     assert len(labels) == 2
     assert labels[0]['bos'] == 0
     assert labels[0]['label'] == 206
     assert labels[1]['bos'] == 1
     assert labels[1]['label'] == 207
     self.ip.route('del', dst='%s/24' % naddr)