4 from requests.auth import HTTPBasicAuth
5 from subprocess import call
18 CONF_TENANT='/restconf/config/policy:tenants'
20 def get(host, port, uri):
21 url='http://'+host+":"+port+uri
22 r = requests.get(url, auth=HTTPBasicAuth(USERNAME, PASSWORD))
25 def put(host, port, uri, data, debug=False):
26 '''Perform a PUT rest operation, using the URL and data provided'''
28 url='http://'+host+":"+port+uri
30 headers = {'Content-type': 'application/yang.data+json',
31 'Accept': 'application/yang.data+json'}
34 print json.dumps(data, indent=4, sort_keys=True)
35 r = requests.put(url, data=json.dumps(data), headers=headers, auth=HTTPBasicAuth(USERNAME, PASSWORD))
40 def post(host, port, uri, data, debug=False):
41 '''Perform a POST rest operation, using the URL and data provided'''
43 url='http://'+host+":"+port+uri
44 headers = {'Content-type': 'application/yang.data+json',
45 'Accept': 'application/yang.data+json'}
48 print json.dumps(data, indent=4, sort_keys=True)
49 r = requests.post(url, data=json.dumps(data), headers=headers, auth=HTTPBasicAuth(USERNAME, PASSWORD))
54 def wait_for_sff_in_datastore(url):
56 resp=get(controller, DEFAULT_PORT, url)
57 if ('192.168.50.71' in resp.text) and ('192.168.50.73' in resp.text):
60 if ('192.168.50.71' not in resp.text):
61 print "ERROR: SFF1 has not been initialized!"
63 if ('192.168.50.73' not in resp.text):
64 print "ERROR: SFF2 has not been initialized!"
69 def get_service_functions_uri():
70 return "/restconf/config/service-function:service-functions"
72 def get_service_functions_data():
74 "service-functions": {
77 "name": "firewall-72",
78 "ip-mgmt-address": "192.168.50.72",
79 "type": "service-function-type:firewall",
81 "sf-data-plane-locator": [
85 "ip": "192.168.50.72",
86 "transport": "service-locator:vxlan-gpe",
87 "service-function-forwarder": "SFF1"
93 "ip-mgmt-address": "192.168.50.74",
94 "type": "service-function-type:dpi",
96 "sf-data-plane-locator": [
100 "ip": "192.168.50.74",
101 "transport": "service-locator:vxlan-gpe",
102 "service-function-forwarder": "SFF2"
110 def get_service_function_forwarders_uri():
111 return "/restconf/config/service-function-forwarder:service-function-forwarders"
113 def get_service_function_forwarders_data():
115 "service-function-forwarders": {
116 "service-function-forwarder": [
119 "service-node": "OVSDB2",
120 "service-function-forwarder-ovs:ovs-bridge": {
123 "service-function-dictionary": [
125 "name": "firewall-72",
126 "sff-sf-data-plane-locator": {
128 "sff-dpl-name": "sfc-tun2"
132 "sff-data-plane-locator": [
135 "data-plane-locator": {
136 "transport": "service-locator:vxlan-gpe",
138 "ip": "192.168.50.71"
140 "service-function-forwarder-ovs:ovs-options": {
157 "service-node": "OVSDB2",
158 "service-function-forwarder-ovs:ovs-bridge": {
161 "service-function-dictionary": [
164 "sff-sf-data-plane-locator": {
166 "sff-dpl-name": "sfc-tun4"
170 "sff-data-plane-locator": [
173 "data-plane-locator": {
174 "transport": "service-locator:vxlan-gpe",
176 "ip": "192.168.50.73"
178 "service-function-forwarder-ovs:ovs-options": {
197 def get_service_function_chains_uri():
198 return "/restconf/config/service-function-chain:service-function-chains/"
200 def get_service_function_chains_data():
202 "service-function-chains": {
203 "service-function-chain": [
206 "symmetric": "false",
207 "sfc-service-function": [
209 "name": "firewall-abstract1",
210 "type": "service-function-type:firewall"
213 "name": "dpi-abstract1",
214 "type": "service-function-type:dpi"
222 def get_service_function_paths_uri():
223 return "/restconf/config/service-function-path:service-function-paths/"
225 def get_service_function_paths_data():
227 "service-function-paths": {
228 "service-function-path": [
230 "name": "SFCGBP-Path",
231 "service-chain-name": "SFCGBP",
232 "starting-index": 255,
240 def get_tenant_data():
245 "name": "DockerTenant",
246 "forwarding-context": {
249 "id": "flood-domain-1",
250 "parent": "bridge-domain1"
253 "id": "flood-domain-2",
254 "parent": "bridge-domain1"
259 "id": "l3-context-vrf-red"
262 "l2-bridge-domain": [
264 "id": "bridge-domain1",
265 "parent": "l3-context-vrf-red"
270 "id": "subnet-10.0.36.0/24",
271 "virtual-router-ip": "10.0.36.1",
272 "parent": "flood-domain-2",
273 "ip-prefix": "10.0.36.1/24"
276 "id": "subnet-10.0.35.0/24",
277 "virtual-router-ip": "10.0.35.1",
278 "parent": "flood-domain-1",
279 "ip-prefix": "10.0.35.1/24"
287 "name": "webservers",
288 "provider-named-selector": [
290 "name": "webservers-clients-icmp-http-contract",
300 "consumer-named-selector": [
302 "name": "webservers-clients-icmp-http-contract",
310 "subject-feature-instances": {
311 "classifier-instance": [
314 "classifier-definition-id": "Classifier-IP-Protocol",
324 "classifier-definition-id": "Classifier-L4",
338 "classifier-definition-id": "Classifier-L4",
354 "action-definition-id": "Action-Chain",
357 "name": "sfc-chain-name",
358 "string-value": "SFCGBP"
364 "action-definition-id": "Action-Allow"
370 "id": "icmp-http-contract",
373 "name": "icmp-subject",
376 "name": "allow-icmp-rule",
381 "instance-name": "icmp",
386 "instance-name": "icmp",
400 "name": "http-subject",
403 "name": "http-chain-rule",
407 "instance-name": "http-dest",
419 "name": "http-out-rule",
423 "instance-name": "http-src",
439 "name": "icmp-http-clause",
453 # Main definition - constants
455 # =======================
457 # =======================
461 # =======================
463 # =======================
467 def get_tenant_uri():
468 return "/restconf/config/policy:tenants/policy:tenant/tenant-red"
470 def get_tunnel_data_1():
475 "ofoverlay:tunnel": [
477 "tunnel-type": "overlay:tunnel-type-vxlan-gpe",
478 "node-connector-id": "openflow:1:1",
479 "ip": "192.168.50.70",
483 "tunnel-type": "overlay:tunnel-type-vxlan",
484 "node-connector-id": "openflow:1:2",
485 "ip": "192.168.50.70",
493 def get_tunnel_uri_1():
494 return "/restconf/config/opendaylight-inventory:nodes/node/openflow:1"
496 def get_tunnel_data_6():
501 "ofoverlay:tunnel": [
503 "tunnel-type": "overlay:tunnel-type-vxlan-gpe",
504 "node-connector-id": "openflow:6:1",
505 "ip": "192.168.50.75",
509 "tunnel-type": "overlay:tunnel-type-vxlan",
510 "node-connector-id": "openflow:6:2",
511 "ip": "192.168.50.75",
519 def get_tunnel_uri_6():
520 return "/restconf/config/opendaylight-inventory:nodes/node/openflow:6"
522 def get_endpoint_data():
527 "endpoint-group": "webservers",
529 "network-containment" : "subnet-10.0.36.0/24",
531 "l2-context": "bridge-domain1",
532 "mac-address": "00:00:00:00:36:02",
536 "ip-address": "10.0.36.2",
537 "l3-context": "l3-context-vrf-red"
540 "port-name": "vethl-h36-2",
541 "tenant": "tenant-red"
546 "endpoint-group": "clients",
547 "network-containment" : "subnet-10.0.35.0/24",
548 "l2-context": "bridge-domain1",
549 "mac-address": "00:00:00:00:35:02",
552 "ip-address": "10.0.35.2",
553 "l3-context": "l3-context-vrf-red"
556 "port-name": "vethl-h35-2",
557 "tenant": "tenant-red"
563 "endpoint-group": "clients",
565 "network-containment" : "subnet-10.0.35.0/24",
567 "l2-context": "bridge-domain1",
568 "mac-address": "00:00:00:00:35:03",
572 "ip-address": "10.0.35.3",
573 "l3-context": "l3-context-vrf-red"
576 "port-name": "vethl-h35-3",
577 "tenant": "tenant-red"
583 "endpoint-group": "webservers",
585 "network-containment" : "subnet-10.0.36.0/24",
587 "l2-context": "bridge-domain1",
588 "mac-address": "00:00:00:00:36:03",
592 "ip-address": "10.0.36.3",
593 "l3-context": "l3-context-vrf-red"
596 "port-name": "vethl-h36-3",
597 "tenant": "tenant-red"
603 "endpoint-group": "webservers",
605 "network-containment" : "subnet-10.0.36.0/24",
607 "l2-context": "bridge-domain1",
608 "mac-address": "00:00:00:00:36:04",
612 "ip-address": "10.0.36.4",
613 "l3-context": "l3-context-vrf-red"
616 "port-name": "vethl-h36-4",
617 "tenant": "tenant-red"
623 "endpoint-group": "clients",
625 "network-containment" : "subnet-10.0.35.0/24",
627 "l2-context": "bridge-domain1",
628 "mac-address": "00:00:00:00:35:04",
632 "ip-address": "10.0.35.4",
633 "l3-context": "l3-context-vrf-red"
636 "port-name": "vethl-h35-4",
637 "tenant": "tenant-red"
643 "endpoint-group": "clients",
645 "network-containment" : "subnet-10.0.35.0/24",
647 "l2-context": "bridge-domain1",
648 "mac-address": "00:00:00:00:35:05",
652 "ip-address": "10.0.35.5",
653 "l3-context": "l3-context-vrf-red"
656 "port-name": "vethl-h35-5",
657 "tenant": "tenant-red"
663 "endpoint-group": "webservers",
665 "network-containment" : "subnet-10.0.36.0/24",
667 "l2-context": "bridge-domain1",
668 "mac-address": "00:00:00:00:36:05",
672 "ip-address": "10.0.36.5",
673 "l3-context": "l3-context-vrf-red"
676 "port-name": "vethl-h36-5",
677 "tenant": "tenant-red"
682 def get_endpoint_uri():
683 return "/restconf/operations/endpoint:register-endpoint"
685 def get_tunnel_oper_uri():
686 return "/restconf/operational/opendaylight-inventory:nodes/"
688 def get_topology_oper_uri():
689 return "/restconf/operational/network-topology:network-topology/topology/ovsdb:1/"
691 if __name__ == "__main__":
695 # Some sensible defaults
696 controller=os.environ.get('ODL')
697 if controller == None:
698 sys.exit("No controller set.")
700 print "Contacting controller at %s" % controller
701 print "waiting for manager on SFFs..."
702 wait_for_sff_in_datastore(get_topology_oper_uri())
703 print "sending service functions"
704 put(controller, DEFAULT_PORT, get_service_functions_uri(), get_service_functions_data(), True)
705 print "sending service function forwarders"
706 put(controller, DEFAULT_PORT, get_service_function_forwarders_uri(), get_service_function_forwarders_data(), True)
707 print "waiting for switches on SFFs..."
708 wait_for_sff_in_datastore(get_tunnel_oper_uri())
709 print "sending service function chains"
710 put(controller, DEFAULT_PORT, get_service_function_chains_uri(), get_service_function_chains_data(), True)
711 print "sending service function paths"
712 put(controller, DEFAULT_PORT, get_service_function_paths_uri(), get_service_function_paths_data(), True)
713 print "sending tunnel"
714 put(controller, DEFAULT_PORT, get_tunnel_uri_1(), get_tunnel_data_1(), True)
715 print "sending tenant"
716 put(controller, DEFAULT_PORT, get_tunnel_uri_6(), get_tunnel_data_6(), True)
717 print "sending tenant"
718 put(controller, DEFAULT_PORT, get_tenant_uri(), get_tenant_data(),True)
719 print "registering endpoints"
720 for endpoint in get_endpoint_data():
721 post(controller, DEFAULT_PORT, get_endpoint_uri(),endpoint,True)