diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-08-10 02:10:59 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-08-12 08:04:31 +0900 |
commit | 5099fbe54de38f09d874e078caaaf4a5adaa66dc (patch) | |
tree | 8a258835a8077a34bb9b23586138f1d2ce3dfb10 /test/scenario_test/lib | |
parent | 5c066cc6a64b03126a737fb41954a62bae762806 (diff) |
test: add flowspec scenario test
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'test/scenario_test/lib')
-rw-r--r-- | test/scenario_test/lib/base.py | 10 | ||||
-rw-r--r-- | test/scenario_test/lib/exabgp.py | 71 | ||||
-rw-r--r-- | test/scenario_test/lib/gobgp.py | 13 | ||||
-rw-r--r-- | test/scenario_test/lib/quagga.py | 14 |
4 files changed, 80 insertions, 28 deletions
diff --git a/test/scenario_test/lib/base.py b/test/scenario_test/lib/base.py index a9bc1b09..f9bdae12 100644 --- a/test/scenario_test/lib/base.py +++ b/test/scenario_test/lib/base.py @@ -218,7 +218,8 @@ class BGPContainer(Container): def add_peer(self, peer, passwd='', evpn=False, is_rs_client=False, policies=None, passive=False, - is_rr_client=False, cluster_id=''): + is_rr_client=False, cluster_id='', + flowspec=False): neigh_addr = '' local_addr = '' for me, you in itertools.product(self.ip_addrs, peer.ip_addrs): @@ -235,6 +236,7 @@ class BGPContainer(Container): self.peers[peer] = {'neigh_addr': neigh_addr, 'passwd': passwd, 'evpn': evpn, + 'flowspec': flowspec, 'is_rs_client': is_rs_client, 'is_rr_client': is_rr_client, 'cluster_id': cluster_id, @@ -257,10 +259,12 @@ class BGPContainer(Container): def enable_peer(self, peer): raise Exception('implement enable_peer() method') - def add_route(self, route, rf='ipv4', attribute=''): + def add_route(self, route, rf='ipv4', attribute=None, matchs=None, thens=None): self.routes[route] = {'prefix': route, 'rf': rf, - 'attr': attribute} + 'attr': attribute, + 'matchs': matchs, + 'thens' : thens} if self.is_running: self.create_config() self.reload_config() diff --git a/test/scenario_test/lib/exabgp.py b/test/scenario_test/lib/exabgp.py index 91919101..9d211342 100644 --- a/test/scenario_test/lib/exabgp.py +++ b/test/scenario_test/lib/exabgp.py @@ -29,10 +29,9 @@ class ExaBGPContainer(BGPContainer): def _start_exabgp(self): cmd = CmdBuffer(' ') - cmd << 'docker exec -d {0}'.format(self.name) cmd << 'env exabgp.log.destination={0}/exabgpd.log'.format(self.SHARED_VOLUME) cmd << './exabgp/sbin/exabgp {0}/exabgpd.conf'.format(self.SHARED_VOLUME) - local(str(cmd), capture=True) + self.local(str(cmd), flag='-d') def _update_exabgp(self): c = CmdBuffer() @@ -51,9 +50,8 @@ class ExaBGPContainer(BGPContainer): local(cmd, capture=True) cmd = 'chmod 755 {0}/update.sh'.format(self.config_dir) local(cmd, capture=True) - cmd = 'docker exec {0} {1}/update.sh'.format(self.name, - self.SHARED_VOLUME) - local(cmd, capture=True) + cmd = '{0}/update.sh'.format(self.SHARED_VOLUME) + self.local(cmd) def run(self): super(ExaBGPContainer, self).run() @@ -78,13 +76,48 @@ class ExaBGPContainer(BGPContainer): cmd << ' local-as {0};'.format(self.asn) cmd << ' peer-as {0};'.format(peer.asn) - cmd << ' static {' - for route, attr in self.routes.iteritems(): - if attr == '': - cmd << ' route {0} next-hop {1};'.format(route, local_addr) - else: - cmd << ' route {0} next-hop {1} attribute {2};'.format(route, local_addr, attr) - cmd << ' }' + routes = [r for r in self.routes.values() if r['rf'] == 'ipv4'] + + if len(routes) > 0: + cmd << ' static {' + for route in routes: + if route['attr']: + cmd << ' route {0} next-hop {1};'.format(route['prefix'], local_addr) + else: + cmd << ' route {0} next-hop {1} attribute {2};'.format(route['prefix'], local_addr, attr) + cmd << ' }' + + routes = [r for r in self.routes.values() if r['rf'] == 'ipv4-flowspec'] + + if len(routes) > 0: + cmd << ' flow {' + for route in routes: + cmd << ' route {0}{{'.format(route['prefix']) + cmd << ' match {' + for match in route['matchs']: + cmd << ' {0};'.format(match) +# cmd << ' source {0};'.format(route['prefix']) +# cmd << ' destination 192.168.0.1/32;' +# cmd << ' destination-port =3128 >8080&<8088;' +# cmd << ' source-port >1024;' +# cmd << ' port =14 =15 >10&<156;' +# cmd << ' protocol udp;' # how to specify multiple ip protocols +# cmd << ' packet-length >1000&<2000;' +# cmd << ' tcp-flags !syn;' + cmd << ' }' + cmd << ' then {' + for then in route['thens']: + cmd << ' {0};'.format(then) +# cmd << ' accept;' +# cmd << ' discard;' +# cmd << ' rate-limit 9600;' +# cmd << ' redirect 1.2.3.4:100;' +# cmd << ' redirect 100:100;' +# cmd << ' mark 10;' +# cmd << ' action sample-terminal;' + cmd << ' }' + cmd << ' }' + cmd << ' }' cmd << '}' with open('{0}/exabgpd.conf'.format(self.config_dir), 'w') as f: @@ -92,8 +125,12 @@ class ExaBGPContainer(BGPContainer): f.write(str(cmd)) def reload_config(self): - cmd = 'docker exec {0} /usr/bin/pkill exabgp -SIGALRM'.format(self.name) - try: - local(cmd, capture=True) - except: - self._start_exabgp() + ps = self.local('ps', capture=True) + running = False + for line in ps.split('\n')[1:]: + if 'python' in line: + running = True + if running: + self.local('/usr/bin/pkill python -SIGUSR1') + else: + self._start_exabgp() diff --git a/test/scenario_test/lib/gobgp.py b/test/scenario_test/lib/gobgp.py index e1da72c8..63f65928 100644 --- a/test/scenario_test/lib/gobgp.py +++ b/test/scenario_test/lib/gobgp.py @@ -148,6 +148,9 @@ class GoBGPContainer(BGPContainer): afi_safi_list.append({'AfiSafiName': 'encap'}) afi_safi_list.append({'AfiSafiName': 'rtc'}) + if info['flowspec']: + afi_safi_list.append({'AfiSafiName': 'ipv4-flowspec'}) + n = {'NeighborConfig': {'NeighborAddress': info['neigh_addr'].split('/')[0], 'PeerAs': peer.asn, @@ -182,6 +185,12 @@ class GoBGPContainer(BGPContainer): cmd = '/usr/bin/pkill gobgpd -SIGHUP' self.local(cmd) for v in self.routes.itervalues(): - cmd = 'gobgp global '\ - 'rib add {0} -a {1}'.format(v['prefix'], v['rf']) + if v['rf'] == 'ipv4' or v['rf'] == 'ipv6': + cmd = 'gobgp global '\ + 'rib add {0} -a {1}'.format(v['prefix'], v['rf']) + elif v['rf']== 'ipv4-flowspec': + cmd = 'gobgp global '\ + 'rib add match {0} then {1} -a {2}'.format(' '.join(v['matchs']), ' '.join(v['thens']), v['rf']) + else: + raise Exception('unsupported route faily: {0}'.format(rf)) self.local(cmd) diff --git a/test/scenario_test/lib/quagga.py b/test/scenario_test/lib/quagga.py index 1099866a..e4de3ef1 100644 --- a/test/scenario_test/lib/quagga.py +++ b/test/scenario_test/lib/quagga.py @@ -161,14 +161,16 @@ class QuaggaBGPContainer(BGPContainer): c << 'neighbor {0} activate'.format(n_addr) c << 'exit-address-family' - for route in self.routes.iterkeys(): - version = netaddr.IPNetwork(route).version - if version == 4: - c << 'network {0}'.format(route) - elif version == 6: + for route in self.routes.itervalues(): + if route['rf'] == 'ipv4': + c << 'network {0}'.format(route['prefix']) + elif route['rf'] == 'ipv6': c << 'address-family ipv6 unicast' - c << 'network {0}'.format(route) + c << 'network {0}'.format(route['prefix']) c << 'exit-address-family' + else: + raise Exception('unsupported route faily: {0}'.format(route['rf'])) + for name, policy in self.policies.iteritems(): c << 'access-list {0} {1} {2}'.format(name, policy['type'], |