summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-05-25 02:43:31 +0000
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-05-25 02:53:42 +0000
commit0dbf1d87cb6f42498e6607d616572fb80d36fd83 (patch)
treea942f671dd44ee75480ad6d3f162d9d29f1be42d /test
parent7c42e295e28c233fdb7a130681cd490308f116ca (diff)
policy: add local-pref action
$ gobgp policy statement st01 add action local-pref 110 Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'test')
-rw-r--r--test/lib/gobgp.py10
-rw-r--r--test/scenario_test/global_policy_test.py28
-rw-r--r--test/scenario_test/noseplugin.py1
3 files changed, 38 insertions, 1 deletions
diff --git a/test/lib/gobgp.py b/test/lib/gobgp.py
index 7faa2198..7627fd50 100644
--- a/test/lib/gobgp.py
+++ b/test/lib/gobgp.py
@@ -87,6 +87,12 @@ class GoBGPContainer(BGPContainer):
if p['type'] == BGP_ATTR_TYPE_NEXT_HOP or p['type'] == BGP_ATTR_TYPE_MP_REACH_NLRI:
return p['nexthop']
+ def _get_local_pref(self, path):
+ for p in path['attrs']:
+ if p['type'] == BGP_ATTR_TYPE_LOCAL_PREF:
+ return p['value']
+ return None
+
def _trigger_peer_cmd(self, cmd, peer):
if peer not in self.peers:
raise Exception('not found peer {0}'.format(peer.router_id))
@@ -117,6 +123,7 @@ class GoBGPContainer(BGPContainer):
for p in d["paths"]:
p["nexthop"] = self._get_nexthop(p)
p["aspath"] = self._get_as_path(p)
+ p["local-pref"] = self._get_local_pref(p)
return ret
def get_global_rib(self, prefix='', rf='ipv4'):
@@ -127,6 +134,7 @@ class GoBGPContainer(BGPContainer):
for p in d["paths"]:
p["nexthop"] = self._get_nexthop(p)
p["aspath"] = self._get_as_path(p)
+ p["local-pref"] = self._get_local_pref(p)
return ret
def monitor_global_rib(self, queue, rf='ipv4'):
@@ -139,6 +147,7 @@ class GoBGPContainer(BGPContainer):
p = json.loads(buf)[0]
p["nexthop"] = self._get_nexthop(p)
p["aspath"] = self._get_as_path(p)
+ p["local-pref"] = self._get_local_pref(p)
queue.put(p)
buf = ''
else:
@@ -165,6 +174,7 @@ class GoBGPContainer(BGPContainer):
p["nexthop"] = self._get_nexthop(p)
p["aspath"] = self._get_as_path(p)
p["prefix"] = p['nlri']['prefix']
+ p["local-pref"] = self._get_local_pref(p)
return ret
def get_adj_rib_in(self, peer, prefix='', rf='ipv4'):
diff --git a/test/scenario_test/global_policy_test.py b/test/scenario_test/global_policy_test.py
index b6f3d86f..b5676727 100644
--- a/test/scenario_test/global_policy_test.py
+++ b/test/scenario_test/global_policy_test.py
@@ -44,7 +44,8 @@ class GoBGPTestBase(unittest.TestCase):
g1 = GoBGPContainer(name='g1', asn=65000, router_id='192.168.0.1',
ctn_image_name=gobgp_ctn_image_name,
- log_level=parser_option.gobgp_log_level)
+ log_level=parser_option.gobgp_log_level,
+ config_format=parser_option.config_format)
q1 = ExaBGPContainer(name='q1', asn=65001, router_id='192.168.0.2')
q2 = ExaBGPContainer(name='q2', asn=65002, router_id='192.168.0.3')
q3 = ExaBGPContainer(name='q3', asn=65003, router_id='192.168.0.4')
@@ -163,6 +164,31 @@ class GoBGPTestBase(unittest.TestCase):
else:
self.assertFalse(community_exists(path, '65100:10'))
+ def test_11_add_ibgp_peer(self):
+ q = ExaBGPContainer(name='q5', asn=65000, router_id='192.168.0.6')
+ time.sleep(q.run())
+ self.quaggas['q5'] = q
+
+ self.gobgp.add_peer(q)
+ q.add_peer(self.gobgp)
+ self.gobgp.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=q)
+
+ def test_12_add_local_pref_policy(self):
+ self.gobgp.local('gobgp policy statement st1 add action accept')
+ self.gobgp.local('gobgp policy statement st1 add action local-pref 300')
+ self.gobgp.local('gobgp policy add p1 st1')
+ self.gobgp.local('gobgp global policy export set p1 default reject')
+ for q in self.quaggas.itervalues():
+ self.gobgp.softreset(q, type='out')
+
+ def test_13_check_adj_rib_out(self):
+ q1 = self.quaggas['q1']
+ for path in self.gobgp.get_adj_rib_out(q1):
+ self.assertTrue(path['local-pref'] == None)
+ q5 = self.quaggas['q5']
+ for path in self.gobgp.get_adj_rib_out(q5):
+ self.assertTrue(path['local-pref'] == 300)
+
if __name__ == '__main__':
if os.geteuid() is not 0:
diff --git a/test/scenario_test/noseplugin.py b/test/scenario_test/noseplugin.py
index ad6c2f13..a53272c3 100644
--- a/test/scenario_test/noseplugin.py
+++ b/test/scenario_test/noseplugin.py
@@ -15,6 +15,7 @@ class OptionParser(Plugin):
parser.add_option('--gobgp-log-level', action="store",
dest="gobgp_log_level", default="info")
parser.add_option('--test-index', action="store", type="int", dest="test_index", default=0)
+ parser.add_option('--config-format', action="store", dest="config_format", default="yaml")
def configure(self, options, conf):
super(OptionParser, self).configure(options, conf)