Advertisement
Guest User

Configuration of OpenDaylight

a guest
Oct 5th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 14.68 KB | None | 0 0
  1. #!/usr/bin/python
  2. import argparse
  3. import requests,json
  4. from requests.auth import HTTPBasicAuth
  5. from subprocess import call
  6. import time
  7. import sys
  8. import os
  9.  
  10. controller='141.3.71.218'
  11. DEFAULT_PORT='8181'
  12.  
  13. USERNAME='...'
  14. PASSWORD='...'
  15.  
  16. def put(host, port, uri, data, debug=False):
  17.     '''Perform a PUT rest operation, using the URL and data provided'''
  18.  
  19.     url='http://'+host+":"+port+uri
  20.  
  21.     headers = {'Content-type': 'application/yang.data+json',
  22.                'Accept': 'application/yang.data+json'}
  23.     if debug == True:
  24.         print "PUT %s" % url
  25.         print json.dumps(data, indent=4, sort_keys=True)
  26.     r = requests.put(url, data=json.dumps(data), headers=headers, auth=HTTPBasicAuth(USERNAME, PASSWORD))
  27.     if debug == True:
  28.         print r.status_code
  29.     r.raise_for_status()
  30.     time.sleep(5)
  31.  
  32. def post(host, port, uri, data, debug=False):
  33.     '''Perform a POST rest operation, using the URL and data provided'''
  34.  
  35.     url='http://'+host+":"+port+uri
  36.     headers = {'Content-type': 'application/yang.data+json',
  37.                'Accept': 'application/yang.data+json'}
  38.     if debug == True:
  39.         print "POST %s" % url
  40.         print json.dumps(data, indent=4, sort_keys=True)
  41.     r = requests.post(url, data=json.dumps(data), headers=headers, auth=HTTPBasicAuth(USERNAME, PASSWORD))
  42.     if debug == True:
  43.         print r.status_code
  44.     r.raise_for_status()
  45.     time.sleep(5)
  46.  
  47. def get_service_nodes_uri():
  48.     return "/restconf/config/service-node:service-nodes"
  49.  
  50. def get_service_nodes_data():
  51.     return {
  52.     "service-nodes": {
  53.         "service-node": [
  54.             {
  55.                 "name": "i72tb18",
  56.                 "service-function": [
  57.                 ],
  58.                 "ip-mgmt-address": "141.3.71.218"
  59.             },
  60.             {
  61.                 "name": "i72tb17",
  62.                 "service-function": [
  63.                 ],
  64.                 "ip-mgmt-address": "141.3.71.217"
  65.             },
  66.             {
  67.                 "name": "i72tb16",
  68.                 "service-function": [
  69.                 ],
  70.                 "ip-mgmt-address": "141.3.71.216"
  71.             },
  72.             {
  73.                 "name": "sff1",
  74.                 "service-function": [
  75.                 ],
  76.                 "ip-mgmt-address": "172.24.4.3"
  77.             },
  78.             {
  79.                 "name": "sf1",
  80.                 "service-function": [
  81.                     "firewall-1"
  82.                 ],
  83.                 "ip-mgmt-address": "172.24.4.4"
  84.             },
  85.         ]
  86.     }
  87. }
  88.  
  89. def get_service_functions_uri():
  90.     return "/restconf/config/service-function:service-functions"
  91.  
  92. def get_service_functions_data():
  93.     return {
  94.     "service-functions": {
  95.         "service-function": [
  96.             {
  97.                 "name": "firewall-1",
  98.                 "ip-mgmt-address": "172.24.4.4",
  99.                 "rest-uri": "http://172.24.4.4:5000",
  100.                 "type": "firewall",
  101.                 "nsh-aware": "true",
  102.                 "sf-data-plane-locator": [
  103.                     {
  104.                         "name": "firewall-1-dpl",
  105.                         "port": 6633,
  106.                         "ip": "172.24.4.4",
  107.                         "transport": "service-locator:vxlan-gpe",
  108.                         "service-function-forwarder": "SFF1"
  109.                     }
  110.                 ]
  111.             }
  112.         ]
  113.     }
  114. }
  115.  
  116. def get_service_function_forwarders_uri():
  117.     return "/restconf/config/service-function-forwarder:service-function-forwarders"
  118.  
  119. def get_service_function_forwarders_data():
  120.     return {
  121.     "service-function-forwarders": {
  122.         "service-function-forwarder": [
  123.            {
  124.                 "name": "Classifiertb18",
  125.                 "service-node": "i72tb18",
  126.                 "service-function-forwarder-ovs:ovs-bridge": {
  127.                     "bridge-name": "br-int",
  128.                 },
  129.                 "sff-data-plane-locator": [
  130.                     {
  131.                         "name": "classifiertb18-dpl",
  132.                         "data-plane-locator": {
  133.                             "transport": "service-locator:vxlan-gpe",
  134.                             "port": 6633,
  135.                             "ip": "141.3.71.18"
  136.                         },
  137.                         "service-function-forwarder-ovs:ovs-options": {
  138.                             "remote-ip": "flow",
  139.                             "dst-port": "6633",
  140.                             "key": "flow",
  141.                             "exts": "gpe",
  142.                             "nsp": "flow",
  143.                             "nsi": "flow",
  144.                             "nshc1": "flow",
  145.                             "nshc2": "flow",
  146.                             "nshc3": "flow",
  147.                             "nshc4": "flow"
  148.                         }
  149.                     }
  150.                 ],
  151.             },
  152.            {
  153.                 "name": "Classifiertb17",
  154.                 "service-node": "i72tb17",
  155.                 "service-function-forwarder-ovs:ovs-bridge": {
  156.                     "bridge-name": "br-int",
  157.                 },
  158.                 "sff-data-plane-locator": [
  159.                     {
  160.                         "name": "classifiertb17-dpl",
  161.                         "data-plane-locator": {
  162.                             "transport": "service-locator:vxlan-gpe",
  163.                             "port": 6633,
  164.                             "ip": "141.3.71.17"
  165.                         },
  166.                         "service-function-forwarder-ovs:ovs-options": {
  167.                             "remote-ip": "flow",
  168.                             "dst-port": "6633",
  169.                             "key": "flow",
  170.                             "exts": "gpe",
  171.                             "nsp": "flow",
  172.                             "nsi": "flow",
  173.                             "nshc1": "flow",
  174.                             "nshc2": "flow",
  175.                             "nshc3": "flow",
  176.                             "nshc4": "flow"
  177.                         }
  178.                     }
  179.                 ],
  180.             },
  181.            {
  182.                 "name": "Classifiertb16",
  183.                 "service-node": "i72tb16",
  184.                 "service-function-forwarder-ovs:ovs-bridge": {
  185.                     "bridge-name": "br-int",
  186.                 },
  187.                 "sff-data-plane-locator": [
  188.                     {
  189.                         "name": "classifiertb16-dpl",
  190.                         "data-plane-locator": {
  191.                             "transport": "service-locator:vxlan-gpe",
  192.                             "port": 6633,
  193.                             "ip": "141.3.71.16"
  194.                         },
  195.                         "service-function-forwarder-ovs:ovs-options": {
  196.                             "remote-ip": "flow",
  197.                             "dst-port": "6633",
  198.                             "key": "flow",
  199.                             "exts": "gpe",
  200.                             "nsp": "flow",
  201.                             "nsi": "flow",
  202.                             "nshc1": "flow",
  203.                             "nshc2": "flow",
  204.                             "nshc3": "flow",
  205.                             "nshc4": "flow"
  206.                         }
  207.                     }
  208.                 ],
  209.             },
  210.             {
  211.                 "name": "SFF1",
  212.                 "service-node": "sff1",
  213.                 "service-function-forwarder-ovs:ovs-bridge": {
  214.                     "bridge-name": "br-int",
  215.                 },
  216.                 "sff-data-plane-locator": [
  217.                     {
  218.                         "name": "sff1-dpl",
  219.                         "data-plane-locator": {
  220.                             "transport": "service-locator:vxlan-gpe",
  221.                             "port": 6633,
  222.                             "ip": "172.24.4.3"
  223.                         },
  224.                         "service-function-forwarder-ovs:ovs-options": {
  225.                             "remote-ip": "flow",
  226.                             "dst-port": "6633",
  227.                             "key": "flow",
  228.                             "exts": "gpe",
  229.                             "nsp": "flow",
  230.                             "nsi": "flow",
  231.                             "nshc1": "flow",
  232.                             "nshc2": "flow",
  233.                             "nshc3": "flow",
  234.                             "nshc4": "flow"
  235.                         }
  236.                     }
  237.                 ],
  238.                 "service-function-dictionary": [
  239.                     {
  240.                         "name": "firewall-1",
  241.                         "sff-sf-data-plane-locator": {
  242.                              "sf-dpl-name": "firewall-1-dpl",
  243.                              "sff-dpl-name": "sff1-dpl"
  244.                         }
  245.                     }
  246.                 ],
  247.             }
  248.         ]
  249.     }
  250. }
  251.  
  252. def get_service_function_chains_uri():
  253.     return "/restconf/config/service-function-chain:service-function-chains/"
  254.  
  255. def get_service_function_chains_data():
  256.     return {
  257.     "service-function-chains": {
  258.         "service-function-chain": [
  259.             {
  260.                 "name": "SFC1",
  261.                 "symmetric": "true",
  262.                 "sfc-service-function": [
  263.                     {
  264.                         "name": "firewall-abstract1",
  265.                         "type": "firewall"
  266.                     }
  267.                 ]
  268.             }
  269.         ]
  270.     }
  271. }
  272.  
  273. def get_service_function_paths_uri():
  274.     return "/restconf/config/service-function-path:service-function-paths/"
  275.  
  276. def get_service_function_paths_data():
  277.     return {
  278.     "service-function-paths": {
  279.         "service-function-path": [
  280.             {
  281.                 "name": "SFP1",
  282.                 "service-chain-name": "SFC1",
  283.                 "starting-index": 255,
  284.                 "symmetric": "true",
  285.                 "context-metadata": "NSH1",
  286.                 "service-path-hop": [
  287.                     {
  288.                         "hop-number": 0,
  289.                         "service-function-name": "firewall-1"
  290.                     }
  291.                 ]
  292.             }
  293.         ]
  294.     }
  295. }
  296.  
  297. def get_service_function_metadata_uri():
  298.     return "/restconf/config/service-function-path-metadata:service-function-metadata/"
  299.  
  300. def get_service_function_metadata_data():
  301.     return {
  302.   "service-function-metadata": {
  303.     "context-metadata": [
  304.       {
  305.         "name": "NSH1",
  306.         "context-header1": "1",
  307.         "context-header2": "2",
  308.         "context-header3": "3",
  309.         "context-header4": "4"
  310.       }
  311.     ]
  312.   }
  313. }
  314.  
  315. def get_rendered_service_path_uri():
  316.     return "/restconf/operations/rendered-service-path:create-rendered-path/"
  317.  
  318. def get_rendered_service_path_data():
  319.     return {
  320.     "input": {
  321.         "name": "RSP1",
  322.         "parent-service-function-path": "SFP1",
  323.         "symmetric": "true"
  324.     }
  325. }
  326.  
  327. def get_service_function_acl_uri():
  328.     return "/restconf/config/ietf-access-control-list:access-lists/"
  329.  
  330. def get_service_function_acl_data():
  331.     return  {
  332.   "access-lists": {
  333.     "acl": [
  334.       {
  335.         "acl-name": "ACL1",
  336.         "acl-type": "ietf-access-control-list:ipv4-acl",
  337.         "access-list-entries": {
  338.           "ace": [
  339.             {
  340.               "rule-name": "ACE1",
  341.               "actions": {
  342.                 "service-function-acl:rendered-service-path": "RSP1"
  343.               },
  344.               "matches": {
  345.                 "destination-ipv4-network": "10.0.0.0/24",
  346.                 "source-ipv4-network": "10.0.0.0/24",
  347.                 "protocol": "6",
  348.                 "source-port-range": {
  349.                     "lower-port": 0
  350.                 },
  351.                 "destination-port-range": {
  352.                     "lower-port": 80
  353.                 }
  354.               }
  355.             }
  356.           ]
  357.         }
  358.       },
  359.       {
  360.         "acl-name": "ACL2",
  361.         "acl-type": "ietf-access-control-list:ipv4-acl",
  362.         "access-list-entries": {
  363.           "ace": [
  364.             {
  365.               "rule-name": "ACE2",
  366.               "actions": {
  367.                 "service-function-acl:rendered-service-path": "RSP1-Reverse"
  368.               },
  369.               "matches": {
  370.                 "destination-ipv4-network": "10.0.0.0/24",
  371.                 "source-ipv4-network": "10.0.0.0/24",
  372.                 "protocol": "6",
  373.                 "source-port-range": {
  374.                     "lower-port": 80
  375.                 },
  376.                 "destination-port-range": {
  377.                     "lower-port": 0
  378.                 }
  379.               }
  380.             }
  381.           ]
  382.         }
  383.       }
  384.     ]
  385.   }
  386. }
  387.  
  388. def get_service_function_classifiers_uri():
  389.     return "/restconf/config/service-function-classifier:service-function-classifiers/"
  390.  
  391. def get_service_function_classifiers_data():
  392.     return  {
  393.   "service-function-classifiers": {
  394.     "service-function-classifier": [
  395.       {
  396.         "name": "ClassifierTo",
  397.         "scl-service-function-forwarder": [
  398.           {
  399.             "name": "Classifiertb18",
  400.             "interface": "tap715148a4-e7"
  401.           }
  402.         ],
  403.         "acl": {
  404.             "name": "ACL1",
  405.             "type": "ietf-access-control-list:ipv4-acl"
  406.          }
  407.       },
  408.       {
  409.         "name": "ClassifierFrom",
  410.         "scl-service-function-forwarder": [
  411.           {
  412.             "name": "Classifiertb18",
  413.             "interface": "tapa679f599-ac"
  414.           }
  415.         ],
  416.         "acl": {
  417.             "name": "ACL2",
  418.             "type": "ietf-access-control-list:ipv4-acl"
  419.          }
  420.       }
  421.     ]
  422.   }
  423. }
  424.  
  425. if __name__ == "__main__":
  426.  
  427.     print "sending service nodes"
  428.     put(controller, DEFAULT_PORT, get_service_nodes_uri(), get_service_nodes_data(), True)
  429.     print "sending service functions"
  430.     put(controller, DEFAULT_PORT, get_service_functions_uri(), get_service_functions_data(), True)
  431.     print "sending service function forwarders"
  432.     put(controller, DEFAULT_PORT, get_service_function_forwarders_uri(), get_service_function_forwarders_data(), True)
  433.     print "sending service function chains"
  434.     put(controller, DEFAULT_PORT, get_service_function_chains_uri(), get_service_function_chains_data(), True)
  435.     print "sending service function metadata"
  436.     put(controller, DEFAULT_PORT, get_service_function_metadata_uri(), get_service_function_metadata_data(), True)
  437.     print "sending service function paths"
  438.     put(controller, DEFAULT_PORT, get_service_function_paths_uri(), get_service_function_paths_data(), True)
  439.     print "sending service function acl"
  440.     put(controller, DEFAULT_PORT, get_service_function_acl_uri(), get_service_function_acl_data(), True)
  441.     print "sending rendered service path"
  442.     post(controller, DEFAULT_PORT, get_rendered_service_path_uri(), get_rendered_service_path_data(), True)
  443.     print "sending service function classifiers"
  444.     put(controller, DEFAULT_PORT, get_service_function_classifiers_uri(), get_service_function_classifiers_data(), True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement