github.com/osrg/gobgp/v3@v3.30.0/test/lib/bagpipe.py (about)

     1  # Copyright (C) 2015 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  from lib.base import (
    18      BGPContainer,
    19      CmdBuffer,
    20      yellow,
    21      local,
    22  )
    23  
    24  
    25  class BagpipeContainer(BGPContainer):
    26  
    27      SHARED_VOLUME = '/root/shared_volume'
    28  
    29      def __init__(self, name, asn, router_id,
    30                   ctn_image_name='yoshima/bagpipe-bgp'):
    31          super(BagpipeContainer, self).__init__(name, asn, router_id,
    32                                                 ctn_image_name)
    33          self.shared_volumes.append((self.config_dir, self.SHARED_VOLUME))
    34  
    35      def run(self):
    36          super(BagpipeContainer, self).run()
    37          cmd = CmdBuffer(' ')
    38          cmd << 'docker exec'
    39          cmd << '{0} cp {1}/bgp.conf'.format(self.name, self.SHARED_VOLUME)
    40          cmd << '/etc/bagpipe-bgp/'
    41          local(str(cmd), capture=True)
    42          cmd = 'docker exec {0} service bagpipe-bgp start'.format(self.name)
    43          local(cmd, capture=True)
    44  
    45      def create_config(self):
    46          c = CmdBuffer()
    47          c << '[BGP]'
    48          if len(self.ip_addrs) > 0:
    49              c << 'local_address={0}'.format(self.ip_addrs[0][1].split('/')[0])
    50          for info in list(self.peers.values()):
    51              c << 'peers={0}'.format(info['neigh_addr'].split('/')[0])
    52          c << 'my_as={0}'.format(self.asn)
    53          c << 'enable_rtc=True'
    54          c << '[API]'
    55          c << 'api_host=localhost'
    56          c << 'api_port=8082'
    57          c << '[DATAPLANE_DRIVER_IPVPN]'
    58          c << 'dataplane_driver = DummyDataplaneDriver'
    59          c << '[DATAPLANE_DRIVER_EVPN]'
    60          c << 'dataplane_driver = DummyDataplaneDriver'
    61  
    62          with open('{0}/bgp.conf'.format(self.config_dir), 'w') as f:
    63              print(yellow(str(c)))
    64              f.writelines(str(c))
    65  
    66      def reload_config(self):
    67          cmd = CmdBuffer(' ')
    68          cmd << 'docker exec'
    69          cmd << '{0} cp {1}/bgp.conf'.format(self.name, self.SHARED_VOLUME)
    70          cmd << '/etc/bagpipe-bgp/'
    71          local(str(cmd), capture=True)
    72          cmd = 'docker exec {0} service bagpipe-bgp restart'.format(self.name)
    73          local(cmd, capture=True)