Last active
November 1, 2017 17:55
-
-
Save fno2010/e3c61ded2510f3a0866595f587369a2f to your computer and use it in GitHub Desktop.
Quickly remove all filtered flows: ./check-flow.sh --filter <flow_name_head> | ./remove-flow.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
FILTER=false | |
while true; do | |
case "$1" in | |
--filter) | |
FILTER=true | |
FILTER_HEAD=$2 | |
shift 2 | |
;; | |
*) | |
CONTROLLER=${1:-localhost} | |
shift | |
break | |
;; | |
esac | |
done | |
if [[ "$FILTER" == "false" ]]; then | |
curl -u admin:admin -H 'Content-Type: application/json' http://$CONTROLLER:8181/restconf/operational/opendaylight-inventory:nodes | jq '.nodes | .node | .[] | ."flow-node-inventory:table" | .[] | .flow' | ack '"id"' | |
else | |
if [[ -n $FILTER_HEAD ]]; then | |
curl -u admin:admin -H 'Content-Type: application/json' http://$CONTROLLER:8181/restconf/operational/opendaylight-inventory:nodes | ./uf-filter.py -H $FILTER_HEAD | |
else | |
curl -u admin:admin -H 'Content-Type: application/json' http://$CONTROLLER:8181/restconf/operational/opendaylight-inventory:nodes | ./uf-filter.py | |
fi | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo '<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
<input xmlns="urn:opendaylight:flow:service"> | |
<barrier>false</barrier> | |
<node xmlns:inv="urn:opendaylight:inventory">/inv:nodes/inv:node[inv:id="'$1'"]</node> | |
<cookie>'$3'</cookie> | |
<table_id>'$2'</table_id> | |
</input>' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CONTROLLER=${1:-localhost} | |
while read line | |
do | |
echo "Removing flows about $line" | |
curl -v -u admin:admin -X POST -d "$(./generate-input.sh $line)" -H 'Content-Type: application/xml' http://$CONTROLLER:8181/restconf/operations/sal-flow:remove-flow | |
done < "${2:-/dev/stdin}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import json | |
def filtered_flow(nodes, head='#UF'): | |
for n in nodes: | |
node_id = n['id'] | |
for t in n.get('flow-node-inventory:table', []): | |
table_id = t['id'] | |
cookies = [] | |
for f in t.get('flow', []): | |
if f['id'].startswith(head) and f['cookie'] not in cookies: | |
cookies.append(f['cookie']) | |
for cookie in cookies: | |
sys.stdout.write("%s %d %s\n" % (node_id, table_id, cookie)) | |
def parse_argument(): | |
import argparse | |
parser = argparse.ArgumentParser(description='ODL Flow Filter.') | |
parser.add_argument('-H', '--head', dest='head', | |
type=str, default='', | |
help='Filter the flow whose name starts with <head>.') | |
parser.add_argument('data', nargs='?') | |
return parser.parse_args(sys.argv[1:]) | |
if '__main__' == __name__: | |
args = parse_argument() | |
if args.data: | |
raw_data = json.load(open(args.data)) | |
else: | |
raw_data = json.load(sys.stdin) | |
filtered_flow(raw_data['nodes']['node'], head=args.head) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Download all the scripts into the same directory and run the following command on the controller host:
If scripts are not on the controller host, you should pass the IP address of the controller host from the command-line argument: