def test_17_check_shutdown(self): g1 = self.gobgp q1 = self.quaggas['q1'] q2 = self.quaggas['q2'] q3 = self.quaggas['q3'] q2.add_route('20.0.0.0/24') q3.add_route('20.0.0.0/24') self.test_01_neighbor_established() self.test_02_check_gobgp_global_rib() paths = q1.get_global_rib('20.0.0.0/24') self.assertEqual(len(paths), 1) n_addrs = [i[1].split('/')[0] for i in self.gobgp.ip_addrs] self.assertIn(paths[0]['nexthop'], n_addrs) q3.stop() self.gobgp.wait_for(expected_state=BGP_FSM_ACTIVE, peer=q3) def f(): paths = q1.get_global_rib('20.0.0.0/24') self.assertEqual(len(paths), 1) self.assertIn(paths[0]['nexthop'], n_addrs) assert_several_times(f) g1.del_peer(q3) del self.quaggas['q3']
def test_02_check_g1_global_rib(self): def f(): rib = self.g1.get_global_rib() self.assertEqual(len(rib), 1) self.assertEqual(len(rib[0]['paths']), 3) assert_several_times(f)
def test_05_check_remove_private_as_peer_all(self): g3 = GoBGPContainer(name='g3', asn=100, router_id='192.168.0.4', ctn_image_name=parser_option.gobgp_image, log_level=parser_option.gobgp_log_level) g4 = GoBGPContainer(name='g4', asn=200, router_id='192.168.0.5', ctn_image_name=parser_option.gobgp_image, log_level=parser_option.gobgp_log_level) time.sleep(max(ctn.run() for ctn in [g3, g4])) self.ctns['g3'] = g3 self.ctns['g4'] = g4 self.g2.add_peer(g3) g3.add_peer(self.g2) g3.add_peer(g4, remove_private_as='all') g4.add_peer(g3) self.g2.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=g3) g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=g4) def f(): rib = g4.get_global_rib() self.assertEqual(len(rib), 1) self.assertEqual(len(rib[0]['paths']), 1) self.assertEqual(rib[0]['paths'][0]['aspath'], [100]) assert_several_times(f)
def test_18_check_withdrawal(self): g1 = self.gobgp q1 = self.quaggas['q1'] q2 = self.quaggas['q2'] g1.add_route('30.0.0.0/24') q1.add_route('30.0.0.0/24') self.test_01_neighbor_established() self.test_02_check_gobgp_global_rib() paths = g1.get_adj_rib_out(q1, '30.0.0.0/24') self.assertEqual(len(paths), 1) self.assertNotIn('source-id', paths[0]) paths = g1.get_adj_rib_out(q2, '30.0.0.0/24') self.assertEqual(len(paths), 1) self.assertNotIn('source-id', paths[0]) g1.local('gobgp global rib del 30.0.0.0/24') def f(): paths = g1.get_adj_rib_out(q1, '30.0.0.0/24') self.assertEqual(len(paths), 0) paths = g1.get_adj_rib_out(q2, '30.0.0.0/24') self.assertEqual(len(paths), 1) self.assertEqual(paths[0]['source-id'], '192.168.0.2') assert_several_times(f)
def test_06_nexthop_unreachable(self): # Test to update the nexthop state if nexthop become unreachable by # link down. If the link r2-r3 and r2-r4 goes down, there is no route # to r3. def _f_r2(): self.assertEqual( self.r2.local( "gobgp global rib -a ipv4 10.3.1.0/24" " | grep '^* ' > /dev/null" " && echo OK || echo NG", capture=True), 'OK') def _f_r1(): self.assertEqual( self.r1.local( "gobgp global rib -a ipv4 10.3.1.0/24" "| grep 'Network not in table' > /dev/null" " && echo OK || echo NG", capture=True), 'OK') ifname = get_ifname_with_prefix('192.168.23.3/24', f=self.r3.local) self.r3.local('ip link set %s down' % ifname) ifname = get_ifname_with_prefix('192.168.24.4/24', f=self.r4.local) self.r4.local('ip link set %s down' % ifname) assert_several_times(f=_f_r2, t=120) assert_several_times(f=_f_r1, t=120) # Confirm the stability of the nexthop state for _ in range(10): time.sleep(1) _f_r2() _f_r1()
def test_03_check_g2_global_rib(self): def f(): rib = self.g2.get_global_rib() self.assertEqual(len(rib), 1) self.assertEqual(len(rib[0]['paths']), 1) self.assertEqual(rib[0]['paths'][0]['aspath'], [100]) assert_several_times(f)
def test_17_check_g2_global_rib(self): def f(): rib = self.g2.get_global_rib() self.assertEqual(len(rib), 1) self.assertEqual(len(rib[0]['paths']), 1) self.assertEqual(rib[0]['paths'][0]['aspath'], [100, 200]) assert_several_times(f)
def test_18_check_g3_global_rib(self): def f(): rib = self.g3.get_global_rib() self.assertEqual(len(rib), 1) self.assertEqual(len(rib[0]['paths']), 2) for path in rib[0]['paths']: self.assertIn(path['aspath'], ([100, 200, 300], [100, 200])) assert_several_times(f)
def test_04_check_accept_as_loop(self): def f(): adj = self.g2.get_neighbor(self.q1)['state']['adj-table'] self.assertTrue('received' in adj) self.assertEqual(adj['received'], 1) self.assertTrue('accepted' in adj) self.assertEqual(adj['accepted'], 1) assert_several_times(f)
def test_04_check_accept_as_loop(self): def f(): s = self.g2.get_neighbor(self.q1)['state'] self.assertTrue('received' in s) self.assertEqual(s.get('received', 0), 1) self.assertTrue('accepted' in s) self.assertEqual(s.get('accepted', 0), 1) assert_several_times(f)
def test_02_check_reject_as_loop(self): def f(): s = self.g2.get_neighbor(self.q1)['state'] self.assertTrue('received' in s) self.assertEqual(s.get('received', 0), 1) # hacky. 'accepted' is zero so the key was deleted due to # omitempty tag in bgp_configs.go. self.assertFalse('accepted' in s) assert_several_times(f)
def test_02_check_reject_as_loop(self): def f(): adj = self.g2.get_neighbor(self.q1)['state']['adj-table'] self.assertTrue('received' in adj) self.assertEqual(adj['received'], 1) # hacky. 'accepted' is zero so the key was deleted due to # omitempty tag in bgp_configs.go. self.assertFalse('accepted' in adj) assert_several_times(f)
def test_02_OSPF_established(self): # Test to start OSPF connection up between r2-r3 and receive the route # to r3's loopback '10.3.1.1'. def _f(): self.assertEqual(self.r2.local( "vtysh -c 'show ip ospf route'" " | grep '10.3.1.1/32' > /dev/null" " && echo OK || echo NG", capture=True), 'OK') assert_several_times(f=_f, t=120)
def test_14_check_g1_global_rib(self): def f(): rib = self.g1.get_global_rib() self.assertEqual(len(rib), 1) self.assertEqual(len(rib[0]['paths']), 3) for path in rib[0]['paths']: self.assertIn(path['aspath'], ([100, 200, 300], [100, 200], [])) if not path['aspath']: # path['aspath'] == [] self.assertEqual(path['local-pref'], 500) assert_several_times(f)
def test_06_check_remove_private_as_peer_replace(self): g3 = self.ctns['g3'] g4 = self.ctns['g4'] g3.update_peer(g4, remove_private_as='replace') g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=g4) def f(): rib = g4.get_global_rib() self.assertEqual(rib[0]['paths'][0]['aspath'], [100, 100, 100, 100]) assert_several_times(f)
def test_03_add_ipv4_route(self): # Test to add IPv4 route to '10.3.1.0/24' whose nexthop is r3's # loopback '10.3.1.1'. Also, test to receive the initial MED/Metric. # MED/Metric = 10(r2 to r3) + 10(r3-ethX to r3-lo) med = 20 self.r2.local( 'gobgp global rib add -a ipv4 10.3.1.0/24 nexthop 10.3.1.1') assert_several_times( f=lambda: self._assert_med_equal(self.r2, '10.3.1.0/24', med)) assert_several_times( f=lambda: self._assert_med_equal(self.r1, '10.3.1.0/24', med)) # Test if the path, which came after the NEXTHOP_UPDATE message was # received from Zebra, is updated by reflecting the nexthop cache. self.r2.local( 'gobgp global rib add -a ipv4 10.3.2.0/24 nexthop 10.3.1.1') assert_several_times( f=lambda: self._assert_med_equal(self.r2, '10.3.2.0/24', med)) assert_several_times( f=lambda: self._assert_med_equal(self.r1, '10.3.2.0/24', med)) self.r2.local( 'gobgp global rib del -a ipv4 10.3.2.0/24')
def test_07_nexthop_restore(self): # Test to update the nexthop state if the Metric to that nexthop is # changed. If the link r2-r3 goes up again, MED/Metric should be update # with the initial value. # MED/Metric = 10(r2 to r3) + 10(r3-ethX to r3-lo) med = 20 ifname = get_ifname_with_prefix('192.168.23.3/24', f=self.r3.local) self.r3.local('ip link set %s up' % ifname) assert_several_times( f=lambda: self._assert_med_equal(self.r2, '10.3.1.0/24', med)) assert_several_times( f=lambda: self._assert_med_equal(self.r1, '10.3.1.0/24', med))
def test_06_link_r2_r4_restore(self): # Test to update the nexthop state if nexthop become reachable again. # If the link r2-r4 goes up again, MED/Metric should be the value of # the path going through r4. # MED/Metric = 10(r2 to r4) + 10(r4 to r3) + 10(r3-ethX to r3-lo) med = 30 ifname = get_ifname_with_prefix('192.168.24.4/24', f=self.r4.local) self.r4.local('ip link set %s up' % ifname) assert_several_times( f=lambda: self._assert_med_equal(self.r2, '10.3.1.0/24', med)) assert_several_times( f=lambda: self._assert_med_equal(self.r1, '10.3.1.0/24', med))
def test_04_link_r2_r3_down(self): # Test to update MED to the nexthop if the Metric to that nexthop is # changed by the link down. If the link r2-r3 goes down, MED/Metric # should be increased. # MED/Metric = 10(r2 to r4) + 10(r4 to r3) + 10(r3-ethX to r3-lo) med = 30 ifname = get_ifname_with_prefix('192.168.23.3/24', f=self.r3.local) self.r3.local('ip link set %s down' % ifname) assert_several_times( f=lambda: self._assert_med_equal(self.r2, '10.3.1.0/24', med)) assert_several_times( f=lambda: self._assert_med_equal(self.r1, '10.3.1.0/24', med))
def test_04_check_accept_as_loop(self): def f(): r = self.g2.get_neighbor(self.q1) self.assertTrue('afi_safis' in r) received = 0 accepted = 0 for afisafi in r['afi_safis']: self.assertTrue('state' in afisafi) s = afisafi.get('state') received += s.get('received') accepted += s.get('accepted') self.assertEqual(received, 1) self.assertEqual(accepted, 1) assert_several_times(f)
def test_02_check_reject_as_loop(self): def f(): r = self.g2.get_neighbor(self.q1) self.assertTrue('afi_safis' in r) received = 0 for afisafi in r['afi_safis']: self.assertTrue('state' in afisafi) s = afisafi.get('state') self.assertTrue('received' in s) received += s.get('received') # hacky. 'accepted' is zero so the key was deleted due to # omitempty tag in bgp_configs.go. self.assertFalse(s.get('accepted'), None) self.assertEqual(received, 1) assert_several_times(f)
def test_07_check_replace_peer_as(self): g5 = GoBGPContainer(name='g5', asn=100, router_id='192.168.0.6', ctn_image_name=parser_option.gobgp_image, log_level=parser_option.gobgp_log_level) time.sleep(g5.run()) g4 = self.ctns['g4'] g4.add_peer(g5, replace_peer_as=True) g5.add_peer(g4) g4.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=g5) def f(): rib = g5.get_global_rib() self.assertEqual(rib[0]['paths'][0]['aspath'], [200, 200, 200, 200, 200]) assert_several_times(f)
def test_03_add_ipv4_route(self): # Test to add IPv4 route to '10.3.1.0/24' whose nexthop is r3's # loopback '10.3.1.1'. Also, test to receive the initial MED/Metric. # MED/Metric = 10(r2 to r3) + 10(r3-ethX to r3-lo) med = 20 def _f_r2(): self._assert_med_equal(self.r2, '10.3.1.0/24', med) def _f_r1(): self._assert_med_equal(self.r1, '10.3.1.0/24', med) self.r2.local( 'gobgp global rib add -a ipv4 10.3.1.0/24 nexthop 10.3.1.1') assert_several_times(f=_f_r2) assert_several_times(f=_f_r1)
def test_05_link_r2_r3_restore(self): # Test to update MED to the nexthop if the Metric to that nexthop is # changed by the link up again. If the link r2-r3 goes up again, # MED/Metric should be update with the initial value. # MED/Metric = 10(r2 to r3) + 10(r3-ethX to r3-lo) med = 20 def _f_r2(): self._assert_med_equal(self.r2, '10.3.1.0/24', med) def _f_r1(): self._assert_med_equal(self.r1, '10.3.1.0/24', med) ifname = get_ifname_with_prefix('192.168.23.3/24', f=self.r3.local) self.r3.local('ip link set %s up' % ifname) assert_several_times(f=_f_r2) assert_several_times(f=_f_r1)
def test_07_nexthop_restore(self): # Test to update the nexthop state if nexthop become reachable again. # If the link r2-r3 and r2-r4 goes up again, MED/Metric should be # update with the initial value. # MED/Metric = 10(r2 to r3) + 10(r3-ethX to r3-lo) med = 20 def _f_r2(): self._assert_med_equal(self.r2, '10.3.1.0/24', med) def _f_r1(): self._assert_med_equal(self.r1, '10.3.1.0/24', med) ifname = get_ifname_with_prefix('192.168.23.3/24', f=self.r3.local) self.r3.local('ip link set %s up' % ifname) ifname = get_ifname_with_prefix('192.168.24.4/24', f=self.r4.local) self.r4.local('ip link set %s up' % ifname) assert_several_times(f=_f_r2) assert_several_times(f=_f_r1)
def test_05_nexthop_unreachable(self): # Test to update the nexthop state if nexthop become unreachable by # link down. If the link r2-r3 and r2-r4 goes down, there is no route # to r3. def _f_r2(prefix): self.assertEqual( self.r2.local( "gobgp global rib -a ipv4 %s" " | grep '^* ' > /dev/null" # not best "*>" " && echo OK || echo NG" % prefix, capture=True), 'OK') def _f_r1(prefix): self.assertEqual( self.r1.local("gobgp global rib -a ipv4 %s" "| grep 'Network not in table' > /dev/null" " && echo OK || echo NG" % prefix, capture=True), 'OK') ifname = get_ifname_with_prefix('192.168.24.4/24', f=self.r4.local) self.r4.local('ip link set %s down' % ifname) assert_several_times(f=lambda: _f_r2("10.3.1.0/24"), t=120) assert_several_times(f=lambda: _f_r1("10.3.1.0/24"), t=120) # Test if the path, which came after the NEXTHOP_UPDATE message was # received from Zebra, is updated by reflecting the nexthop cache. self.r2.local( 'gobgp global rib add -a ipv4 10.3.2.0/24 nexthop 10.3.1.1') assert_several_times(f=lambda: _f_r2("10.3.2.0/24"), t=120) assert_several_times(f=lambda: _f_r1("10.3.2.0/24"), t=120) # Confirm the stability of the nexthop state for _ in range(10): time.sleep(1) _f_r2("10.3.1.0/24") _f_r1("10.3.1.0/24") _f_r2("10.3.2.0/24") _f_r1("10.3.2.0/24")
def test_05_nexthop_unreachable(self): # Test to update the nexthop state if nexthop become unreachable by # link down. If the link r2-r3 and r2-r4 goes down, there is no route # to r3. def _f_r2(prefix): self.assertEqual(self.r2.local( "gobgp global rib -a ipv4 %s" " | grep '^* ' > /dev/null" # not best "*>" " && echo OK || echo NG" % prefix, capture=True), 'OK') def _f_r1(prefix): self.assertEqual(self.r1.local( "gobgp global rib -a ipv4 %s" "| grep 'Network not in table' > /dev/null" " && echo OK || echo NG" % prefix, capture=True), 'OK') ifname = get_ifname_with_prefix('192.168.24.4/24', f=self.r4.local) self.r4.local('ip link set %s down' % ifname) assert_several_times(f=lambda: _f_r2("10.3.1.0/24"), t=120) assert_several_times(f=lambda: _f_r1("10.3.1.0/24"), t=120) # Test if the path, which came after the NEXTHOP_UPDATE message was # received from Zebra, is updated by reflecting the nexthop cache. self.r2.local( 'gobgp global rib add -a ipv4 10.3.2.0/24 nexthop 10.3.1.1') assert_several_times(f=lambda: _f_r2("10.3.2.0/24"), t=120) assert_several_times(f=lambda: _f_r1("10.3.2.0/24"), t=120) # Confirm the stability of the nexthop state for _ in range(10): time.sleep(1) _f_r2("10.3.1.0/24") _f_r1("10.3.1.0/24") _f_r2("10.3.2.0/24") _f_r1("10.3.2.0/24")
def test_04_check_accept_as_loop(self): def f(): self.assertEqual(len(self.g2.get_global_rib()), 1) assert_several_times(f)
def test_02_check_reject_as_loop(self): def f(): self.assertEqual(len(self.g2.get_global_rib()), 0) assert_several_times(f)