github.com/osrg/gobgp@v2.0.0+incompatible/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  from __future__ import absolute_import
    17  
    18  import sys
    19  import time
    20  import unittest
    21  
    22  from fabric.api import local
    23  import nose
    24  
    25  from lib.noseplugin import OptionParser, parser_option
    26  
    27  from lib import base
    28  from lib.base import (
    29      BGP_FSM_ACTIVE,
    30      BGP_FSM_ESTABLISHED,
    31      wait_for_completion,
    32  )
    33  from lib.gobgp import GoBGPContainer
    34  
    35  
    36  class GoBGPTestBase(unittest.TestCase):
    37  
    38      @classmethod
    39      def setUpClass(cls):
    40          gobgp_ctn_image_name = parser_option.gobgp_image
    41          base.TEST_PREFIX = parser_option.test_prefix
    42  
    43          g1 = GoBGPContainer(name='g1', asn=65001, router_id='192.168.0.1',
    44                              ctn_image_name=gobgp_ctn_image_name,
    45                              log_level=parser_option.gobgp_log_level,
    46                              config_format='yaml')
    47          g2 = GoBGPContainer(name='g2', asn=65001, router_id='192.168.0.2',
    48                              ctn_image_name=gobgp_ctn_image_name,
    49                              log_level=parser_option.gobgp_log_level,
    50                              config_format='yaml')
    51          g3 = GoBGPContainer(name='g3', asn=65001, router_id='192.168.0.3',
    52                              ctn_image_name=gobgp_ctn_image_name,
    53                              log_level=parser_option.gobgp_log_level,
    54                              config_format='yaml')
    55          g4 = GoBGPContainer(name='g4', asn=65001, router_id='192.168.0.4',
    56                              ctn_image_name=gobgp_ctn_image_name,
    57                              log_level=parser_option.gobgp_log_level,
    58                              config_format='yaml')
    59          g5 = GoBGPContainer(name='g5', asn=65001, router_id='192.168.0.5',
    60                              ctn_image_name=gobgp_ctn_image_name,
    61                              log_level=parser_option.gobgp_log_level,
    62                              config_format='yaml')
    63  
    64          ctns = [g1, g2, g3, g4, g5]
    65  
    66          initial_wait_time = max(ctn.run() for ctn in ctns)
    67  
    68          time.sleep(initial_wait_time)
    69  
    70          g3.local("gobgp vrf add red rd 10:10 rt both 10:10")
    71          g3.local("gobgp vrf add blue rd 20:20 rt both 20:20")
    72  
    73          g1.add_peer(g3, graceful_restart=True, llgr=True)
    74          g3.add_peer(g1, vrf='red', is_rr_client=True, graceful_restart=True, llgr=True)
    75  
    76          g2.add_peer(g3, graceful_restart=True, llgr=True)
    77          g3.add_peer(g2, vrf='red', is_rr_client=True, graceful_restart=True, llgr=True)
    78  
    79          g4.add_peer(g3, graceful_restart=True, llgr=True)
    80          g3.add_peer(g4, vrf='blue', is_rr_client=True, graceful_restart=True, llgr=True)
    81  
    82          g5.add_peer(g3, graceful_restart=True, llgr=True)
    83          g3.add_peer(g5, vrf='blue', is_rr_client=True, graceful_restart=True, llgr=True)
    84  
    85          cls.g1 = g1
    86          cls.g2 = g2
    87          cls.g3 = g3
    88          cls.g4 = g4
    89          cls.g5 = g5
    90  
    91      # test each neighbor state is turned establish
    92      def test_01_neighbor_established(self):
    93          self.g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=self.g1)
    94          self.g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=self.g2)
    95          self.g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=self.g4)
    96          self.g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=self.g5)
    97  
    98      def test_02_add_routes(self):
    99          self.g1.local("gobgp global rib add 10.0.0.0/24")
   100          self.g4.local("gobgp global rib add 10.0.0.0/24")
   101          wait_for_completion(lambda: len(self.g3.get_global_rib(rf="vpnv4")) == 2)
   102          wait_for_completion(lambda: len(self.g2.get_global_rib()) == 1)
   103          wait_for_completion(lambda: len(self.g5.get_global_rib()) == 1)
   104  
   105      def test_03_disable(self):
   106          self.g3.disable_peer(self.g1)
   107          wait_for_completion(lambda: len(self.g3.get_global_rib(rf="vpnv4")) == 1)
   108          wait_for_completion(lambda: len(self.g2.get_global_rib()) == 0)
   109          wait_for_completion(lambda: len(self.g5.get_global_rib()) == 1)
   110          self.g3.enable_peer(self.g1)
   111          self.g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=self.g1)
   112  
   113      def test_04_softreset_in(self):
   114          self.g3.softreset(self.g1)
   115          wait_for_completion(lambda: len(self.g3.get_global_rib()) == 0)
   116          wait_for_completion(lambda: len(self.g3.get_global_rib(rf="vpnv4")) == 2)
   117          wait_for_completion(lambda: len(self.g2.get_global_rib()) == 1)
   118          wait_for_completion(lambda: len(self.g5.get_global_rib()) == 1)
   119  
   120      def test_05_softreset_out(self):
   121          self.g3.softreset(self.g2, type='out')
   122          wait_for_completion(lambda: len(self.g3.get_global_rib()) == 0)
   123          wait_for_completion(lambda: len(self.g3.get_global_rib(rf="vpnv4")) == 2)
   124          wait_for_completion(lambda: len(self.g2.get_global_rib()) == 1)
   125          wait_for_completion(lambda: len(self.g5.get_global_rib()) == 1)
   126  
   127      def test_06_graceful_restart(self):
   128          self.g1.stop_gobgp()
   129          self.g3.wait_for(expected_state=BGP_FSM_ACTIVE, peer=self.g1)
   130  
   131          wait_for_completion(lambda: len(self.g3.get_global_rib(rf="vpnv4")) == 2)
   132          wait_for_completion(lambda: len(self.g2.get_global_rib()) == 1)
   133  
   134          wait_for_completion(lambda: len(self.g3.get_global_rib(rf="vpnv4")) == 1)
   135          wait_for_completion(lambda: len(self.g2.get_global_rib()) == 0)
   136  
   137  
   138  if __name__ == '__main__':
   139      output = local("which docker 2>&1 > /dev/null ; echo $?", capture=True)
   140      if int(output) is not 0:
   141          print "docker not found"
   142          sys.exit(1)
   143  
   144      nose.main(argv=sys.argv, addplugins=[OptionParser()],
   145                defaultTest=sys.argv[0])