4 from requests.auth import HTTPBasicAuth
5 from subprocess import call
18 OPER_NODES='/restconf/operational/opendaylight-inventory:nodes/'
19 CONF_TENANT='/restconf/config/policy:tenants'
21 def get(host, port, uri):
22 url='http://'+host+":"+port+uri
23 r = requests.get(url, auth=HTTPBasicAuth(USERNAME, PASSWORD))
26 def put(host, port, uri, data, debug=False):
27 '''Perform a PUT rest operation, using the URL and data provided'''
29 url='http://'+host+":"+port+uri
31 headers = {'Content-type': 'application/yang.data+json',
32 'Accept': 'application/yang.data+json'}
35 print json.dumps(data, indent=4, sort_keys=True)
36 r = requests.put(url, data=json.dumps(data), headers=headers, auth=HTTPBasicAuth(USERNAME, PASSWORD))
41 def post(host, port, uri, data, debug=False):
42 '''Perform a POST rest operation, using the URL and data provided'''
44 url='http://'+host+":"+port+uri
45 headers = {'Content-type': 'application/yang.data+json',
46 'Accept': 'application/yang.data+json'}
49 print json.dumps(data, indent=4, sort_keys=True)
50 r = requests.post(url, data=json.dumps(data), headers=headers, auth=HTTPBasicAuth(USERNAME, PASSWORD))
55 def wait_for_sff_in_datastore(url):
57 resp=get(controller, DEFAULT_PORT, url)
58 if ('192.168.50.71' in resp.text) and ('192.168.50.73' in resp.text):
61 if ('192.168.50.71' not in resp.text):
62 print "ERROR: SFF1 has not been initialized!"
64 if ('192.168.50.73' not in resp.text):
65 print "ERROR: SFF2 has not been initialized!"
71 def get_service_functions_uri():
72 return "/restconf/config/service-function:service-functions"
74 def get_service_functions_data():
76 "service-functions": {
79 "name": "firewall-72",
80 "ip-mgmt-address": "192.168.50.72",
81 "type": "service-function-type:firewall",
83 "sf-data-plane-locator": [
87 "ip": "192.168.50.72",
88 "transport": "service-locator:vxlan-gpe",
89 "service-function-forwarder": "SFF1"
95 "ip-mgmt-address": "192.168.50.74",
96 "type": "service-function-type:dpi",
98 "sf-data-plane-locator": [
102 "ip": "192.168.50.74",
103 "transport": "service-locator:vxlan-gpe",
104 "service-function-forwarder": "SFF2"
112 def get_service_function_forwarders_uri():
113 return "/restconf/config/service-function-forwarder:service-function-forwarders"
115 def get_service_function_forwarders_data():
117 "service-function-forwarders": {
118 "service-function-forwarder": [
121 "service-node": "OVSDB2",
122 "service-function-forwarder-ovs:ovs-bridge": {
125 "service-function-dictionary": [
127 "name": "firewall-72",
128 "sff-sf-data-plane-locator": {
130 "sff-dpl-name": "sfc-tun2"
134 "sff-data-plane-locator": [
137 "data-plane-locator": {
138 "transport": "service-locator:vxlan-gpe",
140 "ip": "192.168.50.71"
142 "service-function-forwarder-ovs:ovs-options": {
159 "service-node": "OVSDB2",
160 "service-function-forwarder-ovs:ovs-bridge": {
163 "service-function-dictionary": [
166 "sff-sf-data-plane-locator": {
168 "sff-dpl-name": "sfc-tun4"
172 "sff-data-plane-locator": [
175 "data-plane-locator": {
176 "transport": "service-locator:vxlan-gpe",
178 "ip": "192.168.50.73"
180 "service-function-forwarder-ovs:ovs-options": {
199 def get_service_function_chains_uri():
200 return "/restconf/config/service-function-chain:service-function-chains/"
202 def get_service_function_chains_data():
204 "service-function-chains": {
205 "service-function-chain": [
209 "sfc-service-function": [
211 "name": "firewall-abstract1",
212 "type": "service-function-type:firewall"
215 "name": "dpi-abstract1",
216 "type": "service-function-type:dpi"
224 def get_service_function_paths_uri():
225 return "/restconf/config/service-function-path:service-function-paths/"
227 def get_service_function_paths_data():
229 "service-function-paths": {
230 "service-function-path": [
232 "name": "SFCGBP-Path",
233 "service-chain-name": "SFCGBP",
234 "starting-index": 255,
242 def get_tenant_data():
247 "name": "DockerTenant",
248 "forwarding-context": {
251 "id": "flood-domain-1",
252 "parent": "bridge-domain1"
255 "id": "flood-domain-2",
256 "parent": "bridge-domain1"
261 "id": "l3-context-vrf-red"
264 "l2-bridge-domain": [
266 "id": "bridge-domain1",
267 "parent": "l3-context-vrf-red"
272 "id": "subnet-10.0.36.0/24",
273 "virtual-router-ip": "10.0.36.1",
274 "parent": "flood-domain-2",
275 "ip-prefix": "10.0.36.1/24"
278 "id": "subnet-10.0.35.0/24",
279 "virtual-router-ip": "10.0.35.1",
280 "parent": "flood-domain-1",
281 "ip-prefix": "10.0.35.1/24"
289 "name": "webservers",
290 "provider-named-selector": [
292 "name": "webservers-clients-icmp-http-contract",
302 "consumer-named-selector": [
304 "name": "webservers-clients-icmp-http-contract",
312 "subject-feature-instances": {
313 "classifier-instance": [
316 "classifier-definition-id": "Classifier-IP-Protocol",
326 "classifier-definition-id": "Classifier-L4",
340 "classifier-definition-id": "Classifier-L4",
356 "action-definition-id": "Action-Chain",
359 "name": "sfc-chain-name",
360 "string-value": "SFCGBP"
366 "action-definition-id": "Action-Allow"
372 "id": "icmp-http-contract",
375 "name": "icmp-subject",
378 "name": "allow-icmp-rule",
383 "instance-name": "icmp",
388 "instance-name": "icmp",
402 "name": "http-subject",
405 "name": "http-chain-rule-in",
409 "instance-name": "http-dest",
421 "name": "http-chain-rule-out",
425 "instance-name": "http-src",
441 "name": "icmp-http-clause",
455 # Main definition - constants
457 # =======================
459 # =======================
463 # =======================
465 # =======================
469 def get_tenant_uri():
470 return "/restconf/config/policy:tenants/policy:tenant/tenant-red"
472 def get_tunnel_data_1():
477 "ofoverlay:tunnel": [
479 "tunnel-type": "overlay:tunnel-type-vxlan-gpe",
480 "node-connector-id": "openflow:1:1",
481 "ip": "192.168.50.70",
485 "tunnel-type": "overlay:tunnel-type-vxlan",
486 "node-connector-id": "openflow:1:2",
487 "ip": "192.168.50.70",
495 def get_tunnel_uri_1():
496 return "/restconf/config/opendaylight-inventory:nodes/node/openflow:1"
498 def get_tunnel_data_6():
503 "ofoverlay:tunnel": [
505 "tunnel-type": "overlay:tunnel-type-vxlan-gpe",
506 "node-connector-id": "openflow:6:1",
507 "ip": "192.168.50.75",
511 "tunnel-type": "overlay:tunnel-type-vxlan",
512 "node-connector-id": "openflow:6:2",
513 "ip": "192.168.50.75",
521 def get_tunnel_uri_6():
522 return "/restconf/config/opendaylight-inventory:nodes/node/openflow:6"
524 def get_endpoint_data():
529 "endpoint-group": "webservers",
531 "network-containment" : "subnet-10.0.36.0/24",
533 "l2-context": "bridge-domain1",
534 "mac-address": "00:00:00:00:36:02",
538 "ip-address": "10.0.36.2",
539 "l3-context": "l3-context-vrf-red"
542 "port-name": "vethl-h36-2",
543 "tenant": "tenant-red"
548 "endpoint-group": "clients",
549 "network-containment" : "subnet-10.0.35.0/24",
550 "l2-context": "bridge-domain1",
551 "mac-address": "00:00:00:00:35:02",
554 "ip-address": "10.0.35.2",
555 "l3-context": "l3-context-vrf-red"
558 "port-name": "vethl-h35-2",
559 "tenant": "tenant-red"
565 "endpoint-group": "clients",
567 "network-containment" : "subnet-10.0.35.0/24",
569 "l2-context": "bridge-domain1",
570 "mac-address": "00:00:00:00:35:03",
574 "ip-address": "10.0.35.3",
575 "l3-context": "l3-context-vrf-red"
578 "port-name": "vethl-h35-3",
579 "tenant": "tenant-red"
585 "endpoint-group": "webservers",
587 "network-containment" : "subnet-10.0.36.0/24",
589 "l2-context": "bridge-domain1",
590 "mac-address": "00:00:00:00:36:03",
594 "ip-address": "10.0.36.3",
595 "l3-context": "l3-context-vrf-red"
598 "port-name": "vethl-h36-3",
599 "tenant": "tenant-red"
605 "endpoint-group": "webservers",
607 "network-containment" : "subnet-10.0.36.0/24",
609 "l2-context": "bridge-domain1",
610 "mac-address": "00:00:00:00:36:04",
614 "ip-address": "10.0.36.4",
615 "l3-context": "l3-context-vrf-red"
618 "port-name": "vethl-h36-4",
619 "tenant": "tenant-red"
625 "endpoint-group": "clients",
627 "network-containment" : "subnet-10.0.35.0/24",
629 "l2-context": "bridge-domain1",
630 "mac-address": "00:00:00:00:35:04",
634 "ip-address": "10.0.35.4",
635 "l3-context": "l3-context-vrf-red"
638 "port-name": "vethl-h35-4",
639 "tenant": "tenant-red"
645 "endpoint-group": "clients",
647 "network-containment" : "subnet-10.0.35.0/24",
649 "l2-context": "bridge-domain1",
650 "mac-address": "00:00:00:00:35:05",
654 "ip-address": "10.0.35.5",
655 "l3-context": "l3-context-vrf-red"
658 "port-name": "vethl-h35-5",
659 "tenant": "tenant-red"
665 "endpoint-group": "webservers",
667 "network-containment" : "subnet-10.0.36.0/24",
669 "l2-context": "bridge-domain1",
670 "mac-address": "00:00:00:00:36:05",
674 "ip-address": "10.0.36.5",
675 "l3-context": "l3-context-vrf-red"
678 "port-name": "vethl-h36-5",
679 "tenant": "tenant-red"
683 def get_endpoint_uri():
684 return "/restconf/operations/endpoint:register-endpoint"
686 def get_tunnel_oper_uri():
687 return "/restconf/operational/opendaylight-inventory:nodes/"
689 def get_topology_oper_uri():
690 return "/restconf/operational/network-topology:network-topology/topology/ovsdb:1/"
692 if __name__ == "__main__":
696 # Some sensible defaults
697 controller=os.environ.get('ODL')
698 if controller == None:
699 sys.exit("No controller set.")
701 print "Contacting controller at %s" % controller
702 print "waiting for manager on SFFs..."
703 wait_for_sff_in_datastore(get_topology_oper_uri())
704 print "sending service functions"
705 put(controller, DEFAULT_PORT, get_service_functions_uri(), get_service_functions_data(), True)
706 print "sending service function forwarders"
707 put(controller, DEFAULT_PORT, get_service_function_forwarders_uri(), get_service_function_forwarders_data(), True)
708 print "waiting for switches on SFFs..."
709 wait_for_sff_in_datastore(get_tunnel_oper_uri())
710 print "sending service function chains"
711 put(controller, DEFAULT_PORT, get_service_function_chains_uri(), get_service_function_chains_data(), True)
712 print "sending service function paths"
713 put(controller, DEFAULT_PORT, get_service_function_paths_uri(), get_service_function_paths_data(), True)
714 print "sending tunnel"
715 put(controller, DEFAULT_PORT, get_tunnel_uri_1(), get_tunnel_data_1(), True)
716 print "sending tenant"
717 put(controller, DEFAULT_PORT, get_tunnel_uri_6(), get_tunnel_data_6(), True)
718 print "sending tenant"
719 put(controller, DEFAULT_PORT, get_tenant_uri(), get_tenant_data(),True)
720 print "registering endpoints"
721 for endpoint in get_endpoint_data():
722 post(controller, DEFAULT_PORT, get_endpoint_uri(),endpoint,True)