github.com/osrg/gobgp/v3@v3.30.0/test/scenario_test/vrf_neighbor_test2.py (about)

     1  # Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #    http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    12  # implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  
    17  import sys
    18  import time
    19  import unittest
    20  
    21  import collections
    22  collections.Callable = collections.abc.Callable
    23  
    24  import nose
    25  
    26  from lib.noseplugin import OptionParser, parser_option
    27  
    28  from lib import base
    29  from lib.base import (
    30      BGP_FSM_ACTIVE,
    31      BGP_FSM_ESTABLISHED,
    32      wait_for_completion,
    33      local,
    34  )
    35  from lib.gobgp import GoBGPContainer
    36  
    37  
    38  class GoBGPTestBase(unittest.TestCase):
    39  
    40      @classmethod
    41      def setUpClass(cls):
    42          gobgp_ctn_image_name = parser_option.gobgp_image
    43          base.TEST_PREFIX = parser_option.test_prefix
    44  
    45          g1 = GoBGPContainer(name='g1', asn=65001, router_id='192.168.0.1',
    46                              ctn_image_name=gobgp_ctn_image_name,
    47                              log_level=parser_option.gobgp_log_level,
    48                              config_format='yaml')
    49          g2 = GoBGPContainer(name='g2', asn=65001, router_id='192.168.0.2',
    50                              ctn_image_name=gobgp_ctn_image_name,
    51                              log_level=parser_option.gobgp_log_level,
    52                              config_format='yaml')
    53          g3 = GoBGPContainer(name='g3', asn=65001, router_id='192.168.0.3',
    54                              ctn_image_name=gobgp_ctn_image_name,
    55                              log_level=parser_option.gobgp_log_level,
    56                              config_format='yaml')
    57          g4 = GoBGPContainer(name='g4', asn=65001, router_id='192.168.0.4',
    58                              ctn_image_name=gobgp_ctn_image_name,
    59                              log_level=parser_option.gobgp_log_level,
    60                              config_format='yaml')
    61          g5 = GoBGPContainer(name='g5', asn=65001, router_id='192.168.0.5',
    62                              ctn_image_name=gobgp_ctn_image_name,
    63                              log_level=parser_option.gobgp_log_level,
    64                              config_format='yaml')
    65  
    66          ctns = [g1, g2, g3, g4, g5]
    67  
    68          initial_wait_time = max(ctn.run() for ctn in ctns)
    69  
    70          time.sleep(initial_wait_time)
    71  
    72          g3.local("gobgp vrf add red rd 10:10 rt both 10:10")
    73          g3.local("gobgp vrf add blue rd 20:20 rt both 20:20")
    74  
    75          g1.add_peer(g3, graceful_restart=True, llgr=True)
    76          g3.add_peer(g1, vrf='red', is_rr_client=True, graceful_restart=True, llgr=True)
    77  
    78          g2.add_peer(g3, graceful_restart=True, llgr=True)
    79          g3.add_peer(g2, vrf='red', is_rr_client=True, graceful_restart=True, llgr=True)
    80  
    81          g4.add_peer(g3, graceful_restart=True, llgr=True)
    82          g3.add_peer(g4, vrf='blue', is_rr_client=True, graceful_restart=True, llgr=True)
    83  
    84          g5.add_peer(g3, graceful_restart=True, llgr=True)
    85          g3.add_peer(g5, vrf='blue', is_rr_client=True, graceful_restart=True, llgr=True)
    86  
    87          cls.g1 = g1
    88          cls.g2 = g2
    89          cls.g3 = g3
    90          cls.g4 = g4
    91          cls.g5 = g5
    92  
    93      # test each neighbor state is turned establish
    94      def test_01_neighbor_established(self):
    95          self.g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=self.g1)
    96          self.g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=self.g2)
    97          self.g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=self.g4)
    98          self.g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=self.g5)
    99  
   100      def test_02_add_routes(self):
   101          self.g1.local("gobgp global rib add 10.0.0.0/24")
   102          self.g4.local("gobgp global rib add 10.0.0.0/24")
   103          wait_for_completion(lambda: len(self.g3.get_global_rib(rf="vpnv4")) == 2)
   104          wait_for_completion(lambda: len(self.g2.get_global_rib()) == 1)
   105          wait_for_completion(lambda: len(self.g5.get_global_rib()) == 1)
   106  
   107      def test_03_disable(self):
   108          self.g3.disable_peer(self.g1)
   109          wait_for_completion(lambda: len(self.g3.get_global_rib(rf="vpnv4")) == 1)
   110          wait_for_completion(lambda: len(self.g2.get_global_rib()) == 0)
   111          wait_for_completion(lambda: len(self.g5.get_global_rib()) == 1)
   112          self.g3.enable_peer(self.g1)
   113          self.g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=self.g1)
   114  
   115      def test_04_softreset_in(self):
   116          self.g3.softreset(self.g1)
   117          wait_for_completion(lambda: len(self.g3.get_global_rib()) == 0)
   118          wait_for_completion(lambda: len(self.g3.get_global_rib(rf="vpnv4")) == 2)
   119          wait_for_completion(lambda: len(self.g2.get_global_rib()) == 1)
   120          wait_for_completion(lambda: len(self.g5.get_global_rib()) == 1)
   121  
   122      def test_05_softreset_out(self):
   123          self.g3.softreset(self.g2, type='out')
   124          wait_for_completion(lambda: len(self.g3.get_global_rib()) == 0)
   125          wait_for_completion(lambda: len(self.g3.get_global_rib(rf="vpnv4")) == 2)
   126          wait_for_completion(lambda: len(self.g2.get_global_rib()) == 1)
   127          wait_for_completion(lambda: len(self.g5.get_global_rib()) == 1)
   128  
   129      def test_06_graceful_restart(self):
   130          self.g1.stop_gobgp()
   131          self.g3.wait_for(expected_state=BGP_FSM_ACTIVE, peer=self.g1)
   132  
   133          wait_for_completion(lambda: len(self.g3.get_global_rib(rf="vpnv4")) == 2)
   134          wait_for_completion(lambda: len(self.g2.get_global_rib()) == 1)
   135  
   136          wait_for_completion(lambda: len(self.g3.get_global_rib(rf="vpnv4")) == 1)
   137          wait_for_completion(lambda: len(self.g2.get_global_rib()) == 0)
   138  
   139  
   140  if __name__ == '__main__':
   141      output = local("which docker 2>&1 > /dev/null ; echo $?", capture=True)
   142      if int(output) != 0:
   143          print("docker not found")
   144          sys.exit(1)
   145  
   146      nose.main(argv=sys.argv, addplugins=[OptionParser()],
   147                defaultTest=sys.argv[0])