summaryrefslogtreecommitdiffhomepage
path: root/test/scenario_test
diff options
context:
space:
mode:
Diffstat (limited to 'test/scenario_test')
-rw-r--r--test/scenario_test/bgp_router_test.py31
-rw-r--r--test/scenario_test/ibgp_router_test.py8
-rw-r--r--test/scenario_test/lib/base.py4
-rw-r--r--test/scenario_test/lib/exabgp.py2
-rw-r--r--test/scenario_test/lib/gobgp.py23
-rw-r--r--test/scenario_test/lib/quagga.py13
-rw-r--r--test/scenario_test/route_server_policy_grpc_test.py30
-rw-r--r--test/scenario_test/route_server_policy_test.py30
8 files changed, 96 insertions, 45 deletions
diff --git a/test/scenario_test/bgp_router_test.py b/test/scenario_test/bgp_router_test.py
index 804003aa..7e985552 100644
--- a/test/scenario_test/bgp_router_test.py
+++ b/test/scenario_test/bgp_router_test.py
@@ -95,7 +95,7 @@ class GoBGPTestBase(unittest.TestCase):
def test_03_check_gobgp_adj_out_rib(self):
for q in self.quaggas.itervalues():
for path in self.gobgp.get_adj_rib_out(q):
- asns = path['as_path']
+ asns = path['aspath']
self.assertTrue(self.gobgp.asn in asns)
# check routes are properly advertised to all BGP speaker
@@ -219,7 +219,7 @@ class GoBGPTestBase(unittest.TestCase):
self.assertTrue(len(dst[0]['paths']) == 1)
path = dst[0]['paths'][0]
self.assertTrue(path['nexthop'] == '0.0.0.0')
- self.assertTrue(len(path['as_path']) == 0)
+ self.assertTrue(len(path['aspath']) == 0)
def test_11_check_adj_rib_out(self):
for q in self.quaggas.itervalues():
@@ -229,7 +229,7 @@ class GoBGPTestBase(unittest.TestCase):
peer_info = self.gobgp.peers[q]
local_addr = peer_info['local_addr'].split('/')[0]
self.assertTrue(path['nexthop'] == local_addr)
- self.assertTrue(path['as_path'] == [self.gobgp.asn])
+ self.assertTrue(path['aspath'] == [self.gobgp.asn])
def test_12_disable_peer(self):
q1 = self.quaggas['q1']
@@ -262,12 +262,37 @@ class GoBGPTestBase(unittest.TestCase):
ctn_image_name=self.gobgp.image,
log_level=parser_option.gobgp_log_level)
g2.run()
+ self.quaggas['g2'] = g2
br01 = self.bridges['br01']
br01.addif(g2)
g2.add_peer(g1, passive=True)
g1.add_peer(g2)
g1.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=g2)
+ def test_16_check_local_pref_and_med_handling(self):
+ g1 = self.gobgp
+ g1.add_route('10.20.0.0/24', local_pref=1000, med=2000)
+ # iBGP peer
+ g2 = self.quaggas['g2']
+ paths = g2.get_global_rib('10.20.0.0/24')
+ self.assertTrue(len(paths) == 1)
+ self.assertTrue(len(paths[0]['paths']) == 1)
+ path = paths[0]['paths'][0]
+ local_pref = extract_path_attribute(path, BGP_ATTR_TYPE_LOCAL_PREF)
+ self.assertTrue(local_pref['value'] == 1000)
+ med = extract_path_attribute(path, BGP_ATTR_TYPE_MULTI_EXIT_DISC)
+ self.assertTrue(med['metric'] == 2000)
+
+ # eBGP peer
+ q1 = self.quaggas['q1']
+ paths = q1.get_global_rib('10.20.0.0/24')
+ self.assertTrue(len(paths) == 1)
+ path = paths[0]
+ local_pref = extract_path_attribute(path, BGP_ATTR_TYPE_LOCAL_PREF)
+ # local_pref's default value is 100
+ self.assertTrue(local_pref['value'] == 100)
+ med = extract_path_attribute(path, BGP_ATTR_TYPE_MULTI_EXIT_DISC)
+ self.assertTrue(med['metric'] == 2000)
if __name__ == '__main__':
if os.geteuid() is not 0:
diff --git a/test/scenario_test/ibgp_router_test.py b/test/scenario_test/ibgp_router_test.py
index 65d6cb99..aa27c20d 100644
--- a/test/scenario_test/ibgp_router_test.py
+++ b/test/scenario_test/ibgp_router_test.py
@@ -104,7 +104,7 @@ class GoBGPTestBase(unittest.TestCase):
self.assertTrue(len(dst[0]['paths']) == 1)
path = dst[0]['paths'][0]
self.assertTrue(path['nexthop'] == '0.0.0.0')
- self.assertTrue(len(path['as_path']) == 0)
+ self.assertTrue(len(path['aspath']) == 0)
def test_05_check_gobgp_adj_rib_out(self):
for q in self.quaggas.itervalues():
@@ -115,7 +115,7 @@ class GoBGPTestBase(unittest.TestCase):
peer_info = self.gobgp.peers[q]
local_addr = peer_info['local_addr'].split('/')[0]
self.assertTrue(path['nexthop'] == local_addr)
- self.assertTrue(len(path['as_path']) == 0)
+ self.assertTrue(len(path['aspath']) == 0)
# check routes are properly advertised to all BGP speaker
def test_06_check_quagga_global_rib(self):
@@ -181,7 +181,7 @@ class GoBGPTestBase(unittest.TestCase):
peer_info = self.gobgp.peers[q3]
local_addr = peer_info['local_addr'].split('/')[0]
self.assertTrue(path['nexthop'] == local_addr)
- self.assertTrue(path['as_path'] == [self.gobgp.asn])
+ self.assertTrue(path['aspath'] == [self.gobgp.asn])
def test_10_check_gobgp_ibgp_adj_rib_out(self):
q1 = self.quaggas['q1']
@@ -198,7 +198,7 @@ class GoBGPTestBase(unittest.TestCase):
self.assertTrue(path['nexthop'] == neigh_addr)
# bgp router mustn't change aspath of routes from eBGP peers
# which are sent to iBGP peers
- self.assertTrue(path['as_path'] == [q3.asn])
+ self.assertTrue(path['aspath'] == [q3.asn])
# disable ebgp peer, check ebgp routes are removed
def test_11_disable_ebgp_peer(self):
diff --git a/test/scenario_test/lib/base.py b/test/scenario_test/lib/base.py
index 8a81c245..d3cb9bd9 100644
--- a/test/scenario_test/lib/base.py
+++ b/test/scenario_test/lib/base.py
@@ -286,7 +286,8 @@ class BGPContainer(Container):
def add_route(self, route, rf='ipv4', attribute=None, aspath=None,
community=None, med=None, extendedcommunity=None,
- nexthop=None, matchs=None, thens=None):
+ nexthop=None, matchs=None, thens=None,
+ local_pref=None):
self.routes[route] = {'prefix': route,
'rf': rf,
'attr': attribute,
@@ -294,6 +295,7 @@ class BGPContainer(Container):
'as-path': aspath,
'community': community,
'med': med,
+ 'local-pref': local_pref,
'extended-community': extendedcommunity,
'matchs': matchs,
'thens' : thens}
diff --git a/test/scenario_test/lib/exabgp.py b/test/scenario_test/lib/exabgp.py
index af310530..e14a084b 100644
--- a/test/scenario_test/lib/exabgp.py
+++ b/test/scenario_test/lib/exabgp.py
@@ -93,6 +93,8 @@ class ExaBGPContainer(BGPContainer):
r << 'community [{0}]'.format(' '.join(c for c in route['community']))
if route['med']:
r << 'med {0}'.format(route['med'])
+ if route['local-pref']:
+ r << 'local-preference {0}'.format(route['local-pref'])
if route['extended-community']:
r << 'extended-community [{0}]'.format(route['extended-community'])
if route['attr']:
diff --git a/test/scenario_test/lib/gobgp.py b/test/scenario_test/lib/gobgp.py
index f126047d..042d6696 100644
--- a/test/scenario_test/lib/gobgp.py
+++ b/test/scenario_test/lib/gobgp.py
@@ -18,6 +18,11 @@ import json
import toml
from itertools import chain
+def extract_path_attribute(path, typ):
+ for a in path['attrs']:
+ if a['type'] == typ:
+ return a
+ return None
class GoBGPContainer(BGPContainer):
@@ -105,7 +110,7 @@ class GoBGPContainer(BGPContainer):
for d in ret:
for p in d["paths"]:
p["nexthop"] = self._get_nexthop(p)
- p["as_path"] = self._get_as_path(p)
+ p["aspath"] = self._get_as_path(p)
return ret
def get_global_rib(self, prefix='', rf='ipv4'):
@@ -115,7 +120,7 @@ class GoBGPContainer(BGPContainer):
for d in ret:
for p in d["paths"]:
p["nexthop"] = self._get_nexthop(p)
- p["as_path"] = self._get_as_path(p)
+ p["aspath"] = self._get_as_path(p)
return ret
def _get_adj_rib(self, adj_type, peer, prefix='', rf='ipv4'):
@@ -129,7 +134,7 @@ class GoBGPContainer(BGPContainer):
ret = [p["paths"][0] for p in json.loads(output)]
for p in ret:
p["nexthop"] = self._get_nexthop(p)
- p["as_path"] = self._get_as_path(p)
+ p["aspath"] = self._get_as_path(p)
return ret
def get_adj_rib_in(self, peer, prefix='', rf='ipv4'):
@@ -308,8 +313,16 @@ class GoBGPContainer(BGPContainer):
self.local(cmd)
for v in self.routes.itervalues():
if v['rf'] == 'ipv4' or v['rf'] == 'ipv6':
- cmd = 'gobgp global '\
- 'rib add {0} -a {1}'.format(v['prefix'], v['rf'])
+ r = CmdBuffer(' ')
+ r << 'gobgp global -a {0}'.format(v['rf'])
+ r << 'rib add {0}'.format(v['prefix'])
+ if v['next-hop']:
+ r << 'nexthop {0}'.format(v['next-hop'])
+ if v['local-pref']:
+ r << 'local-pref {0}'.format(v['local-pref'])
+ if v['med']:
+ r << 'med {0}'.format(v['med'])
+ cmd = str(r)
elif v['rf'] == 'ipv4-flowspec' or v['rf'] == 'ipv6-flowspec':
cmd = 'gobgp global '\
'rib add match {0} then {1} -a {2}'.format(' '.join(v['matchs']), ' '.join(v['thens']), v['rf'])
diff --git a/test/scenario_test/lib/quagga.py b/test/scenario_test/lib/quagga.py
index 6001d9a3..17f855a9 100644
--- a/test/scenario_test/lib/quagga.py
+++ b/test/scenario_test/lib/quagga.py
@@ -108,10 +108,19 @@ class QuaggaBGPContainer(BGPContainer):
lines = lines[2:] # other useless lines
else:
raise Exception('unknown output format {0}'.format(lines))
- nexthop = lines[1].split()[0].strip()
aspath = [int(asn) for asn in lines[0].split()]
+ nexthop = lines[1].split()[0].strip()
+ info = [s.strip(',') for s in lines[2].split()]
+ attrs = []
+ if 'metric' in info:
+ med = info[info.index('metric') + 1]
+ attrs.append({'type': BGP_ATTR_TYPE_MULTI_EXIT_DISC, 'metric': int(med)})
+ if 'localpref' in info:
+ localpref = info[info.index('localpref') + 1]
+ attrs.append({'type': BGP_ATTR_TYPE_LOCAL_PREF, 'value': int(localpref)})
+
rib.append({'prefix': prefix, 'nexthop': nexthop,
- 'aspath': aspath})
+ 'aspath': aspath, 'attrs': attrs})
return rib
def get_neighbor_state(self, peer):
diff --git a/test/scenario_test/route_server_policy_grpc_test.py b/test/scenario_test/route_server_policy_grpc_test.py
index 06f72e3c..2bf84654 100644
--- a/test/scenario_test/route_server_policy_grpc_test.py
+++ b/test/scenario_test/route_server_policy_grpc_test.py
@@ -2137,19 +2137,19 @@ class ExportPolicyAsPathPrepend(object):
q2 = env.q2
path = g1.get_adj_rib_out(q1, prefix='192.168.20.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
path = g1.get_adj_rib_out(q1, prefix='192.168.200.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
path = g1.get_local_rib(q2, prefix='192.168.20.0/24')[0]['paths'][0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.20.0/24')[0]
- env.assertTrue(path['as_path'] == [65005]*5 + [e1.asn])
+ env.assertTrue(path['aspath'] == [65005]*5 + [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.200.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
@register_scenario
@@ -2199,19 +2199,19 @@ class ImportPolicyAsPathPrependLastAS(object):
q2 = env.q2
path = g1.get_adj_rib_out(q1, prefix='192.168.20.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
path = g1.get_adj_rib_out(q1, prefix='192.168.200.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
path = g1.get_local_rib(q2, prefix='192.168.20.0/24')[0]['paths'][0]
- env.assertTrue(path['as_path'] == [e1.asn]*5 + [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn]*5 + [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.20.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn]*5 + [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn]*5 + [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.200.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
@register_scenario
@@ -2261,19 +2261,19 @@ class ExportPolicyAsPathPrependLastAS(object):
q2 = env.q2
path = g1.get_adj_rib_out(q1, prefix='192.168.20.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
path = g1.get_adj_rib_out(q1, prefix='192.168.200.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
path = g1.get_local_rib(q2, prefix='192.168.20.0/24')[0]['paths'][0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.20.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn]*5 + [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn]*5 + [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.200.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
@register_scenario
diff --git a/test/scenario_test/route_server_policy_test.py b/test/scenario_test/route_server_policy_test.py
index 773e5ce7..e21b7713 100644
--- a/test/scenario_test/route_server_policy_test.py
+++ b/test/scenario_test/route_server_policy_test.py
@@ -2440,19 +2440,19 @@ class ExportPolicyAsPathPrepend(object):
q2 = env.q2
path = g1.get_adj_rib_out(q1, prefix='192.168.20.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
path = g1.get_adj_rib_out(q1, prefix='192.168.200.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
path = g1.get_local_rib(q2, prefix='192.168.20.0/24')[0]['paths'][0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.20.0/24')[0]
- env.assertTrue(path['as_path'] == [65005]*5 + [e1.asn])
+ env.assertTrue(path['aspath'] == [65005]*5 + [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.200.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
@register_scenario
@@ -2511,19 +2511,19 @@ class ImportPolicyAsPathPrependLastAS(object):
q2 = env.q2
path = g1.get_adj_rib_out(q1, prefix='192.168.20.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
path = g1.get_adj_rib_out(q1, prefix='192.168.200.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
path = g1.get_local_rib(q2, prefix='192.168.20.0/24')[0]['paths'][0]
- env.assertTrue(path['as_path'] == [e1.asn]*5 + [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn]*5 + [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.20.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn]*5 + [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn]*5 + [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.200.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
@register_scenario
@@ -2582,19 +2582,19 @@ class ExportPolicyAsPathPrependLastAS(object):
q2 = env.q2
path = g1.get_adj_rib_out(q1, prefix='192.168.20.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
path = g1.get_adj_rib_out(q1, prefix='192.168.200.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
path = g1.get_local_rib(q2, prefix='192.168.20.0/24')[0]['paths'][0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.20.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn]*5 + [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn]*5 + [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.200.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
+ env.assertTrue(path['aspath'] == [e1.asn])
@register_scenario