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": {
158 "service-node": "OVSDB2",
159 "service-function-forwarder-ovs:ovs-bridge": {
162 "service-function-dictionary": [
165 "sff-sf-data-plane-locator": {
167 "sff-dpl-name": "sfc-tun4"
171 "sff-data-plane-locator": [
174 "data-plane-locator": {
175 "transport": "service-locator:vxlan-gpe",
177 "ip": "192.168.50.73"
179 "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": [
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():
244 "id": "tenant-dobre",
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"
394 "name": "http-subject",
397 "name": "http-chain-rule-in",
401 "instance-name": "http-dest",
413 "name": "http-chain-rule-out",
417 "instance-name": "http-src",
433 "name": "icmp-http-clause",
447 # Main definition - constants
449 # =======================
451 # =======================
455 # =======================
457 # =======================
461 def get_tenant_uri():
462 return "/restconf/config/policy:tenants/policy:tenant/tenant-dobre"
464 def get_tunnel_data_1():
469 "ofoverlay:tunnel": [
471 "tunnel-type": "overlay:tunnel-type-vxlan-gpe",
472 "node-connector-id": "openflow:1:1",
473 "ip": "192.168.50.70",
477 "tunnel-type": "overlay:tunnel-type-vxlan",
478 "node-connector-id": "openflow:1:2",
479 "ip": "192.168.50.70",
487 def get_tunnel_uri_1():
488 return "/restconf/config/opendaylight-inventory:nodes/node/openflow:1"
490 def get_tunnel_data_6():
495 "ofoverlay:tunnel": [
497 "tunnel-type": "overlay:tunnel-type-vxlan-gpe",
498 "node-connector-id": "openflow:6:1",
499 "ip": "192.168.50.75",
503 "tunnel-type": "overlay:tunnel-type-vxlan",
504 "node-connector-id": "openflow:6:2",
505 "ip": "192.168.50.75",
513 def get_tunnel_uri_6():
514 return "/restconf/config/opendaylight-inventory:nodes/node/openflow:6"
516 def get_endpoint_data():
521 "endpoint-group": "webservers",
523 "network-containment" : "subnet-10.0.36.0/24",
525 "l2-context": "bridge-domain1",
526 "mac-address": "00:00:00:00:36:02",
530 "ip-address": "10.0.36.2",
531 "l3-context": "l3-context-vrf-red"
534 "port-name": "vethl-h36_2",
535 "tenant": "tenant-dobre"
540 "endpoint-group": "clients",
541 "network-containment" : "subnet-10.0.35.0/24",
542 "l2-context": "bridge-domain1",
543 "mac-address": "00:00:00:00:35:02",
546 "ip-address": "10.0.35.2",
547 "l3-context": "l3-context-vrf-red"
550 "port-name": "vethl-h35_2",
551 "tenant": "tenant-dobre"
557 "endpoint-group": "clients",
559 "network-containment" : "subnet-10.0.35.0/24",
561 "l2-context": "bridge-domain1",
562 "mac-address": "00:00:00:00:35:03",
566 "ip-address": "10.0.35.3",
567 "l3-context": "l3-context-vrf-red"
570 "port-name": "vethl-h35_3",
571 "tenant": "tenant-dobre"
577 "endpoint-group": "webservers",
579 "network-containment" : "subnet-10.0.36.0/24",
581 "l2-context": "bridge-domain1",
582 "mac-address": "00:00:00:00:36:03",
586 "ip-address": "10.0.36.3",
587 "l3-context": "l3-context-vrf-red"
590 "port-name": "vethl-h36_3",
591 "tenant": "tenant-dobre"
597 "endpoint-group": "webservers",
599 "network-containment" : "subnet-10.0.36.0/24",
601 "l2-context": "bridge-domain1",
602 "mac-address": "00:00:00:00:36:04",
606 "ip-address": "10.0.36.4",
607 "l3-context": "l3-context-vrf-red"
610 "port-name": "vethl-h36_4",
611 "tenant": "tenant-dobre"
617 "endpoint-group": "clients",
619 "network-containment" : "subnet-10.0.35.0/24",
621 "l2-context": "bridge-domain1",
622 "mac-address": "00:00:00:00:35:04",
626 "ip-address": "10.0.35.4",
627 "l3-context": "l3-context-vrf-red"
630 "port-name": "vethl-h35_4",
631 "tenant": "tenant-dobre"
637 "endpoint-group": "clients",
639 "network-containment" : "subnet-10.0.35.0/24",
641 "l2-context": "bridge-domain1",
642 "mac-address": "00:00:00:00:35:05",
646 "ip-address": "10.0.35.5",
647 "l3-context": "l3-context-vrf-red"
650 "port-name": "vethl-h35_5",
651 "tenant": "tenant-dobre"
657 "endpoint-group": "webservers",
659 "network-containment" : "subnet-10.0.36.0/24",
661 "l2-context": "bridge-domain1",
662 "mac-address": "00:00:00:00:36:05",
666 "ip-address": "10.0.36.5",
667 "l3-context": "l3-context-vrf-red"
670 "port-name": "vethl-h36_5",
671 "tenant": "tenant-dobre"
675 def get_endpoint_uri():
676 return "/restconf/operations/endpoint:register-endpoint"
678 def get_tunnel_oper_uri():
679 return "/restconf/operational/opendaylight-inventory:nodes/"
681 def get_topology_oper_uri():
682 return "/restconf/operational/network-topology:network-topology/topology/ovsdb:1/"
684 if __name__ == "__main__":
688 # Some sensible defaults
689 controller=os.environ.get('ODL')
690 if controller == None:
691 sys.exit("No controller set.")
693 print "Contacting controller at %s" % controller
694 print "waiting for manager on SFFs..."
695 wait_for_sff_in_datastore(get_topology_oper_uri())
696 print "sending service functions"
697 put(controller, DEFAULT_PORT, get_service_functions_uri(), get_service_functions_data(), True)
698 print "sending service function forwarders"
699 put(controller, DEFAULT_PORT, get_service_function_forwarders_uri(), get_service_function_forwarders_data(), True)
700 print "waiting for switches on SFFs..."
701 wait_for_sff_in_datastore(get_tunnel_oper_uri())
702 print "sending service function chains"
703 put(controller, DEFAULT_PORT, get_service_function_chains_uri(), get_service_function_chains_data(), True)
704 print "sending service function paths"
705 put(controller, DEFAULT_PORT, get_service_function_paths_uri(), get_service_function_paths_data(), True)
706 print "sending tunnel"
707 put(controller, DEFAULT_PORT, get_tunnel_uri_1(), get_tunnel_data_1(), True)
708 print "sending tenant"
709 put(controller, DEFAULT_PORT, get_tunnel_uri_6(), get_tunnel_data_6(), True)
710 print "sending tenant"
711 put(controller, DEFAULT_PORT, get_tenant_uri(), get_tenant_data(),True)
712 print "registering endpoints"
713 for endpoint in get_endpoint_data():
714 post(controller, DEFAULT_PORT, get_endpoint_uri(),endpoint,True)