github.com/osrg/gobgp@v2.0.0+incompatible/test/scenario_test/route_server_softreset_test.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 BGP_FSM_ESTABLISHED
    29  from lib.gobgp import GoBGPContainer
    30  
    31  
    32  class GoBGPTestBase(unittest.TestCase):
    33  
    34      wait_per_retry = 5
    35      retry_limit = 15
    36  
    37      @classmethod
    38      def setUpClass(cls):
    39          gobgp_ctn_image_name = parser_option.gobgp_image
    40          base.TEST_PREFIX = parser_option.test_prefix
    41  
    42          g1 = GoBGPContainer(name='g1', asn=65000, router_id='192.168.0.1',
    43                              ctn_image_name=gobgp_ctn_image_name,
    44                              log_level=parser_option.gobgp_log_level)
    45          g2 = GoBGPContainer(name='g2', asn=65001, router_id='192.168.0.2',
    46                              ctn_image_name=gobgp_ctn_image_name,
    47                              log_level=parser_option.gobgp_log_level)
    48          g3 = GoBGPContainer(name='g3', asn=65002, router_id='192.168.0.3',
    49                              ctn_image_name=gobgp_ctn_image_name,
    50                              log_level=parser_option.gobgp_log_level)
    51          g4 = GoBGPContainer(name='g4', asn=65003, router_id='192.168.0.4',
    52                              ctn_image_name=gobgp_ctn_image_name,
    53                              log_level=parser_option.gobgp_log_level)
    54          ctns = [g1, g2, g3, g4]
    55  
    56          # advertise a route from route-server-clients
    57          cls.clients = {}
    58          for cli in [g2, g3, g4]:
    59              cls.clients[cli.name] = cli
    60          initial_wait_time = max(ctn.run() for ctn in ctns)
    61  
    62          time.sleep(initial_wait_time)
    63  
    64          for cli in cls.clients.itervalues():
    65              g1.add_peer(cli, is_rs_client=True, passwd='passwd', passive=True, prefix_limit=10)
    66              cli.add_peer(g1, passwd='passwd')
    67  
    68          cls.gobgp = g1
    69  
    70      # test each neighbor state is turned establish
    71      def test_01_neighbor_established(self):
    72          for cli in self.clients.itervalues():
    73              self.gobgp.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=cli)
    74  
    75      def test_02_softresetin_test1(self):
    76          g1 = self.gobgp
    77          g2 = self.clients['g2']
    78          g3 = self.clients['g3']
    79  
    80          p1 = {'ip-prefix': '10.0.10.0/24'}
    81          p2 = {'ip-prefix': '10.0.20.0/24'}
    82  
    83          ps0 = {'prefix-set-name': 'ps0', 'prefix-list': [p1, p2]}
    84          g1.set_prefix_set(ps0)
    85  
    86          st0 = {'conditions': {'match-prefix-set': {'prefix-set': 'ps0'}},
    87                 'actions': {'route-disposition': 'accept-route'}}
    88  
    89          pol0 = {'name': 'pol0', 'statements': [st0]}
    90  
    91          _filename = g1.add_policy(pol0, g3, 'import', 'reject')
    92  
    93          g3.add_route('10.0.10.0/24')
    94          g3.add_route('10.0.20.0/24')
    95  
    96          time.sleep(1)
    97  
    98          num = g2.get_neighbor(g1)['state']['messages']['received'].get('update', 0)
    99          num = g2.get_neighbor(g1)['state']['messages']['received'].get('update', 0)
   100  
   101          ps0 = {'prefix-set-name': 'ps0', 'prefix-list': [p1]}
   102          g1.set_prefix_set(ps0)
   103          g1.create_config()
   104          # this will cause g1 to do softresetin for all neighbors (policy is changed)
   105          g1.reload_config()
   106  
   107          time.sleep(1)
   108  
   109          num2 = g2.get_neighbor(g1)['state']['messages']['received'].get('update', 0)
   110          self.assertEqual((num + 1), num2)
   111  
   112          g3.softreset(g1, type='out')
   113  
   114          time.sleep(1)
   115  
   116          num3 = g2.get_neighbor(g1)['state']['messages']['received'].get('update', 0)
   117          self.assertEqual(num2, num3)
   118  
   119      def test_03_softresetin_test2(self):
   120          g1 = self.gobgp
   121          g2 = self.clients['g2']
   122  
   123          g2.add_route('10.0.10.0/24')
   124          time.sleep(1)
   125  
   126          num = g2.get_neighbor(g1)['state']['messages']['received'].get('update', 0)
   127          time.sleep(3)
   128  
   129          g1.local('gobgp n all softresetin')
   130          time.sleep(3)
   131  
   132          num1 = g2.get_neighbor(g1)['state']['messages']['received'].get('update', 0)
   133  
   134          self.assertEqual(num, num1)
   135  
   136  
   137  if __name__ == '__main__':
   138      output = local("which docker 2>&1 > /dev/null ; echo $?", capture=True)
   139      if int(output) is not 0:
   140          print "docker not found"
   141          sys.exit(1)
   142  
   143      nose.main(argv=sys.argv, addplugins=[OptionParser()],
   144                defaultTest=sys.argv[0])