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