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.70' in resp.text) and ('192.168.50.71' in resp.text):
60 if ('192.168.50.70' not in resp.text):
61 print "ERROR: SFF1 has not been initialized!"
63 if ('192.168.50.71' 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": "sw1-vxlangpe-0"
132 "sff-data-plane-locator": [
134 "name": "sw1-vxlangpe-0",
135 "data-plane-locator": {
136 "transport": "service-locator:vxlan-gpe",
138 "ip": "192.168.50.70"
140 "service-function-forwarder-ovs:ovs-options": {
156 "service-node": "OVSDB2",
157 "service-function-forwarder-ovs:ovs-bridge": {
160 "service-function-dictionary": [
163 "sff-sf-data-plane-locator": {
165 "sff-dpl-name": "sw2-vxlangpe-0"
169 "sff-data-plane-locator": [
171 "name": "sw2-vxlangpe-0",
172 "data-plane-locator": {
173 "transport": "service-locator:vxlan-gpe",
175 "ip": "192.168.50.71"
177 "service-function-forwarder-ovs:ovs-options": {
195 def get_service_function_chains_uri():
196 return "/restconf/config/service-function-chain:service-function-chains/"
198 def get_service_function_chains_data():
200 "service-function-chains": {
201 "service-function-chain": [
205 "sfc-service-function": [
207 "name": "firewall-abstract1",
208 "type": "service-function-type:firewall"
211 "name": "dpi-abstract1",
212 "type": "service-function-type:dpi"
220 def get_service_function_paths_uri():
221 return "/restconf/config/service-function-path:service-function-paths/"
223 def get_service_function_paths_data():
225 "service-function-paths": {
226 "service-function-path": [
228 "name": "SFCGBP-Path",
229 "service-chain-name": "SFCGBP",
230 "starting-index": 255,
238 def get_tenant_data():
243 "name": "DockerTenant",
244 "forwarding-context": {
247 "id": "flood-domain-1",
248 "parent": "bridge-domain1"
251 "id": "flood-domain-2",
252 "parent": "bridge-domain1"
257 "id": "l3-context-vrf-red"
260 "l2-bridge-domain": [
262 "id": "bridge-domain1",
263 "parent": "l3-context-vrf-red"
268 "id": "subnet-10.0.36.0/24",
269 "virtual-router-ip": "10.0.36.1",
270 "parent": "flood-domain-2",
271 "ip-prefix": "10.0.36.1/24"
274 "id": "subnet-10.0.35.0/24",
275 "virtual-router-ip": "10.0.35.1",
276 "parent": "flood-domain-1",
277 "ip-prefix": "10.0.35.1/24"
285 "name": "webservers",
286 "provider-named-selector": [
288 "name": "webservers-clients-icmp-http-contract",
298 "consumer-named-selector": [
300 "name": "webservers-clients-icmp-http-contract",
308 "subject-feature-instances": {
309 "classifier-instance": [
312 "classifier-definition-id": "Classifier-IP-Protocol",
322 "classifier-definition-id": "Classifier-L4",
336 "classifier-definition-id": "Classifier-L4",
352 "action-definition-id": "Action-Chain",
355 "name": "sfc-chain-name",
356 "string-value": "SFCGBP"
362 "action-definition-id": "Action-Allow"
368 "id": "icmp-http-contract",
371 "name": "icmp-subject",
374 "name": "allow-icmp-rule",
379 "instance-name": "icmp",
384 "instance-name": "icmp",
398 "name": "http-subject",
401 "name": "http-chain-rule",
405 "instance-name": "http-dest",
417 "name": "http-out-rule",
421 "instance-name": "http-src",
437 "name": "icmp-http-clause",
451 # Main definition - constants
453 # =======================
455 # =======================
459 # =======================
461 # =======================
465 def get_tenant_uri():
466 return "/restconf/config/policy:tenants/policy:tenant/tenant-red"
468 def get_tunnel_data_1():
473 "ofoverlay:tunnel": [
475 "tunnel-type": "overlay:tunnel-type-vxlan-gpe",
476 "node-connector-id": "openflow:1:1",
477 "ip": "192.168.50.70",
481 "tunnel-type": "overlay:tunnel-type-vxlan",
482 "node-connector-id": "openflow:1:2",
483 "ip": "192.168.50.70",
491 def get_tunnel_uri_1():
492 return "/restconf/config/opendaylight-inventory:nodes/node/openflow:1"
494 def get_tunnel_data_6():
499 "ofoverlay:tunnel": [
501 "tunnel-type": "overlay:tunnel-type-vxlan-gpe",
502 "node-connector-id": "openflow:6:1",
503 "ip": "192.168.50.75",
507 "tunnel-type": "overlay:tunnel-type-vxlan",
508 "node-connector-id": "openflow:6:2",
509 "ip": "192.168.50.75",
517 def get_tunnel_uri_6():
518 return "/restconf/config/opendaylight-inventory:nodes/node/openflow:6"
520 def get_endpoint_data():
525 "endpoint-group": "webservers",
527 "network-containment" : "subnet-10.0.36.0/24",
529 "l2-context": "bridge-domain1",
530 "mac-address": "00:00:00:00:36:02",
534 "ip-address": "10.0.36.2",
535 "l3-context": "l3-context-vrf-red"
538 "port-name": "vethl-h36-2",
539 "tenant": "tenant-red"
544 "endpoint-group": "clients",
545 "network-containment" : "subnet-10.0.35.0/24",
546 "l2-context": "bridge-domain1",
547 "mac-address": "00:00:00:00:35:02",
550 "ip-address": "10.0.35.2",
551 "l3-context": "l3-context-vrf-red"
554 "port-name": "vethl-h35-2",
555 "tenant": "tenant-red"
561 "endpoint-group": "clients",
563 "network-containment" : "subnet-10.0.35.0/24",
565 "l2-context": "bridge-domain1",
566 "mac-address": "00:00:00:00:35:03",
570 "ip-address": "10.0.35.3",
571 "l3-context": "l3-context-vrf-red"
574 "port-name": "vethl-h35-3",
575 "tenant": "tenant-red"
581 "endpoint-group": "webservers",
583 "network-containment" : "subnet-10.0.36.0/24",
585 "l2-context": "bridge-domain1",
586 "mac-address": "00:00:00:00:36:03",
590 "ip-address": "10.0.36.3",
591 "l3-context": "l3-context-vrf-red"
594 "port-name": "vethl-h36-3",
595 "tenant": "tenant-red"
601 "endpoint-group": "webservers",
603 "network-containment" : "subnet-10.0.36.0/24",
605 "l2-context": "bridge-domain1",
606 "mac-address": "00:00:00:00:36:04",
610 "ip-address": "10.0.36.4",
611 "l3-context": "l3-context-vrf-red"
614 "port-name": "vethl-h36-4",
615 "tenant": "tenant-red"
621 "endpoint-group": "clients",
623 "network-containment" : "subnet-10.0.35.0/24",
625 "l2-context": "bridge-domain1",
626 "mac-address": "00:00:00:00:35:04",
630 "ip-address": "10.0.35.4",
631 "l3-context": "l3-context-vrf-red"
634 "port-name": "vethl-h35-4",
635 "tenant": "tenant-red"
641 "endpoint-group": "clients",
643 "network-containment" : "subnet-10.0.35.0/24",
645 "l2-context": "bridge-domain1",
646 "mac-address": "00:00:00:00:35:05",
650 "ip-address": "10.0.35.5",
651 "l3-context": "l3-context-vrf-red"
654 "port-name": "vethl-h35-5",
655 "tenant": "tenant-red"
661 "endpoint-group": "webservers",
663 "network-containment" : "subnet-10.0.36.0/24",
665 "l2-context": "bridge-domain1",
666 "mac-address": "00:00:00:00:36:05",
670 "ip-address": "10.0.36.5",
671 "l3-context": "l3-context-vrf-red"
674 "port-name": "vethl-h36-5",
675 "tenant": "tenant-red"
680 def get_endpoint_uri():
681 return "/restconf/operations/endpoint:register-endpoint"
683 def get_tunnel_oper_uri():
684 return "/restconf/operational/opendaylight-inventory:nodes/"
686 def get_topology_oper_uri():
687 return "/restconf/operational/network-topology:network-topology/topology/ovsdb:1/"
689 if __name__ == "__main__":
693 # Some sensible defaults
694 controller=os.environ.get('ODL')
695 if controller == None:
696 sys.exit("No controller set.")
698 print "Contacting controller at %s" % controller
699 print "waiting for manager on SFFs..."
700 wait_for_sff_in_datastore(get_topology_oper_uri())
701 print "sending service functions"
702 put(controller, DEFAULT_PORT, get_service_functions_uri(), get_service_functions_data(), True)
703 print "sending service function forwarders"
704 put(controller, DEFAULT_PORT, get_service_function_forwarders_uri(), get_service_function_forwarders_data(), True)
705 print "waiting for switches on SFFs..."
706 wait_for_sff_in_datastore(get_tunnel_oper_uri())
707 print "sending service function chains"
708 put(controller, DEFAULT_PORT, get_service_function_chains_uri(), get_service_function_chains_data(), True)
709 print "sending service function paths"
710 put(controller, DEFAULT_PORT, get_service_function_paths_uri(), get_service_function_paths_data(), True)
711 print "sending tunnel"
712 put(controller, DEFAULT_PORT, get_tunnel_uri_1(), get_tunnel_data_1(), True)
713 print "sending tenant"
714 put(controller, DEFAULT_PORT, get_tunnel_uri_6(), get_tunnel_data_6(), True)
715 print "sending tenant"
716 put(controller, DEFAULT_PORT, get_tenant_uri(), get_tenant_data(),True)
717 print "registering endpoints"
718 for endpoint in get_endpoint_data():
719 post(controller, DEFAULT_PORT, get_endpoint_uri(),endpoint,True)