diff options
Diffstat (limited to 'test/lib')
-rw-r--r-- | test/lib/base.py | 5 | ||||
-rw-r--r-- | test/lib/gobgp.py | 29 | ||||
-rw-r--r-- | test/lib/quagga.py | 23 |
3 files changed, 50 insertions, 7 deletions
diff --git a/test/lib/base.py b/test/lib/base.py index 9dc44e82..b0f66ec4 100644 --- a/test/lib/base.py +++ b/test/lib/base.py @@ -327,7 +327,7 @@ class BGPContainer(Container): graceful_restart=None, local_as=None, prefix_limit=None, v6=False, llgr=None, vrf='', interface='', allow_as_in=0, remove_private_as=None, replace_peer_as=False, addpath=False, - treat_as_withdraw=False): + treat_as_withdraw=False, remote_as=None): neigh_addr = '' local_addr = '' it = itertools.product(self.ip_addrs, peer.ip_addrs) @@ -373,7 +373,8 @@ class BGPContainer(Container): 'remove_private_as': remove_private_as, 'replace_peer_as': replace_peer_as, 'addpath': addpath, - 'treat_as_withdraw': treat_as_withdraw} + 'treat_as_withdraw': treat_as_withdraw, + 'remote_as': remote_as or peer.asn} if self.is_running and reload_config: self.create_config() self.reload_config() diff --git a/test/lib/gobgp.py b/test/lib/gobgp.py index 7fa90291..601883e5 100644 --- a/test/lib/gobgp.py +++ b/test/lib/gobgp.py @@ -27,6 +27,7 @@ from fabric.utils import indent import netaddr import toml import yaml +import collections from lib.base import ( BGPContainer, @@ -55,7 +56,7 @@ class GoBGPContainer(BGPContainer): def __init__(self, name, asn, router_id, ctn_image_name='osrg/gobgp', log_level='debug', zebra=False, config_format='toml', - zapi_version=2, ospfd_config=None): + zapi_version=2, bgp_config=None, ospfd_config=None): super(GoBGPContainer, self).__init__(name, asn, router_id, ctn_image_name) self.shared_volumes.append((self.config_dir, self.SHARED_VOLUME)) @@ -72,6 +73,20 @@ class GoBGPContainer(BGPContainer): self.zapi_version = zapi_version self.config_format = config_format + # bgp_config is equivalent to config.BgpConfigSet structure + # Example: + # bgp_config = { + # 'global': { + # 'confederation': { + # 'config': { + # 'identifier': 10, + # 'member-as-list': [65001], + # } + # }, + # }, + # } + self.bgp_config = bgp_config or {} + # To start OSPFd in GoBGP container, specify 'ospfd_config' as a dict # type value. # Example: @@ -294,6 +309,14 @@ class GoBGPContainer(BGPContainer): if self.ospfd_config: self._create_config_ospfd() + def _merge_dict(self, dct, merge_dct): + for k, v in merge_dct.iteritems(): + if (k in dct and isinstance(dct[k], dict) + and isinstance(merge_dct[k], collections.Mapping)): + self._merge_dict(dct[k], merge_dct[k]) + else: + dct[k] = merge_dct[k] + def _create_config_bgp(self): config = { 'global': { @@ -310,6 +333,8 @@ class GoBGPContainer(BGPContainer): 'neighbors': [], } + self._merge_dict(config, self.bgp_config) + if self.zebra and self.zapi_version == 2: config['global']['use-multiple-paths'] = {'config': {'enabled': True}} @@ -349,7 +374,7 @@ class GoBGPContainer(BGPContainer): 'config': { 'neighbor-address': neigh_addr, 'neighbor-interface': interface, - 'peer-as': peer.asn, + 'peer-as': info['remote_as'], 'auth-password': info['passwd'], 'vrf': info['vrf'], 'remove-private-as': info['remove_private_as'], diff --git a/test/lib/quagga.py b/test/lib/quagga.py index 86a468d8..8f5f17c1 100644 --- a/test/lib/quagga.py +++ b/test/lib/quagga.py @@ -38,12 +38,24 @@ class QuaggaBGPContainer(BGPContainer): WAIT_FOR_BOOT = 1 SHARED_VOLUME = '/etc/quagga' - def __init__(self, name, asn, router_id, ctn_image_name='osrg/quagga', zebra=False): + def __init__(self, name, asn, router_id, ctn_image_name='osrg/quagga', bgpd_config=None, zebra=False): super(QuaggaBGPContainer, self).__init__(name, asn, router_id, ctn_image_name) self.shared_volumes.append((self.config_dir, self.SHARED_VOLUME)) self.zebra = zebra + # bgp_config is equivalent to config.BgpConfigSet structure + # Example: + # bgpd_config = { + # 'global': { + # 'confederation': { + # 'identifier': 10, + # 'peers': [65001], + # }, + # }, + # } + self.bgpd_config = bgpd_config or {} + def run(self): super(QuaggaBGPContainer, self).run() return self.WAIT_FOR_BOOT @@ -160,14 +172,19 @@ class QuaggaBGPContainer(BGPContainer): if any(info['graceful_restart'] for info in self.peers.itervalues()): c << 'bgp graceful-restart' + if 'global' in self.bgpd_config: + if 'confederation' in self.bgpd_config['global']: + conf = self.bgpd_config['global']['confederation']['config'] + c << 'bgp confederation identifier {0}'.format(conf['identifier']) + c << 'bgp confederation peers {0}'.format(' '.join([str(i) for i in conf['member-as-list']])) + version = 4 for peer, info in self.peers.iteritems(): version = netaddr.IPNetwork(info['neigh_addr']).version n_addr = info['neigh_addr'].split('/')[0] if version == 6: c << 'no bgp default ipv4-unicast' - - c << 'neighbor {0} remote-as {1}'.format(n_addr, peer.asn) + c << 'neighbor {0} remote-as {1}'.format(n_addr, info['remote_as']) if info['is_rs_client']: c << 'neighbor {0} route-server-client'.format(n_addr) for typ, p in info['policies'].iteritems(): |