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

     1  # Copyright (C) 2017 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 unittest
    18  from lib import base
    19  from lib.base import BGP_FSM_ESTABLISHED, local
    20  from lib.gobgp import GoBGPContainer
    21  import sys
    22  import os
    23  import time
    24  
    25  import collections
    26  collections.Callable = collections.abc.Callable
    27  
    28  import nose
    29  from lib.noseplugin import OptionParser, parser_option
    30  from itertools import combinations
    31  
    32  
    33  class GoBGPTestBase(unittest.TestCase):
    34  
    35      @classmethod
    36      def setUpClass(cls):
    37          gobgp_ctn_image_name = parser_option.gobgp_image
    38          base.TEST_PREFIX = parser_option.test_prefix
    39  
    40          g1 = GoBGPContainer(name='g1', asn=65000, router_id='192.168.0.1',
    41                              ctn_image_name=gobgp_ctn_image_name,
    42                              log_level=parser_option.gobgp_log_level)
    43          g2 = GoBGPContainer(name='g2', asn=65001, router_id='192.168.0.2',
    44                              ctn_image_name=gobgp_ctn_image_name,
    45                              log_level=parser_option.gobgp_log_level)
    46          ctns = [g1, g2]
    47  
    48          initial_wait_time = max(ctn.run() for ctn in ctns)
    49  
    50          time.sleep(initial_wait_time + 2)
    51  
    52          done = False
    53  
    54          def f(ifname, ctn):
    55              out = ctn.local('ip -6 n', capture=True)
    56              l = [line for line in out.split('\n') if ifname in line]
    57              if len(l) == 0:
    58                  return False
    59              elif len(l) > 1:
    60                  raise Exception('not p2p link')
    61              return 'REACHABLE' in l[0]
    62  
    63          for i in range(20):
    64              g1.local('ping6 -c 1 ff02::1%eth0')
    65              g2.local('ping6 -c 1 ff02::1%eth0')
    66              if f('eth0', g1) and f('eth0', g2):
    67                  done = True
    68                  break
    69              time.sleep(1)
    70  
    71          if not done:
    72              raise Exception('timeout')
    73  
    74          for a, b in combinations(ctns, 2):
    75              a.add_peer(b, interface='eth0')
    76              b.add_peer(a, interface='eth0')
    77  
    78          cls.g1 = g1
    79          cls.g2 = g2
    80  
    81      # test each neighbor state is turned establish
    82      def test_01_neighbor_established(self):
    83          self.g1.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=self.g2)
    84  
    85      def test_02_add_ipv4_route(self):
    86  
    87          self.g1.add_route('10.0.0.0/24')
    88  
    89          time.sleep(1)
    90  
    91          rib = self.g2.get_global_rib(rf='ipv4')
    92          self.assertEqual(len(rib), 1)
    93  
    94  
    95  if __name__ == '__main__':
    96      output = local("which docker 2>&1 > /dev/null ; echo $?", capture=True)
    97      if int(output) != 0:
    98          print("docker not found")
    99          sys.exit(1)
   100  
   101      nose.main(argv=sys.argv, addplugins=[OptionParser()],
   102                defaultTest=sys.argv[0])