Matteo Scandolo | 4e0e88c | 2017-08-08 13:05:25 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Rizwan Haider | 51fdb3f | 2016-11-09 18:29:32 -0500 | [diff] [blame] | 17 | from xos.logger import Logger, logging |
| 18 | from synchronizers.vnodlocal.pseudowireproviders.pseudowireprovider import PseudowireProvider |
| 19 | from services.metronetwork.models import NetworkEdgeToEdgePointConnection, NetworkEdgePort |
| 20 | |
| 21 | import requests, json |
| 22 | from requests.auth import HTTPBasicAuth |
| 23 | |
| 24 | logger = Logger(level=logging.INFO) |
| 25 | |
| 26 | class SegmentRoutingVlanXconnectPseudowireProvider(PseudowireProvider): |
| 27 | |
| 28 | def __init__(self, **args): |
| 29 | pass |
| 30 | |
| 31 | # Methods to support creation |
| 32 | # |
| 33 | # Returns: handle |
| 34 | # |
| 35 | def create(self, port1, port2, vlanid, pseudowireservice): |
| 36 | # Create method - create xconnect |
| 37 | # Vlan is TBD |
| 38 | pseudowirename = ("port1: %s, port2: %s, vlan: %s" % (port1, port2, vlanid)) |
| 39 | logger.info("SegmentRoutingXConnect create called, name: %s" % pseudowirename ) |
| 40 | |
| 41 | # Pull out Ports from FQN |
| 42 | |
| 43 | |
| 44 | # Pull out Device from FQN |
| 45 | # Use default user/password? |
| 46 | |
| 47 | # curl --user onos:rocks -X POST -H "Content-Type: application/json" http://138.120.151.126:8181/onos/v1/network/configuration/apps/org.onosproject.segmentrouting/xconnect -d '{ "of:0000000000000001" : [{"vlan" : "100", "ports" : [1, 2], "name" : "Mike"}] }' |
| 48 | |
| 49 | # Port 1 Device and Num |
| 50 | port1IdToken = port1.split('/', 1) |
| 51 | port1Devicename = port1IdToken[0] |
| 52 | port1Num = port1IdToken[1] |
| 53 | |
| 54 | # Port 2 Device and Num |
| 55 | port2IdToken = port2.split('/', 1) |
| 56 | port2Devicename = port2IdToken[0] |
| 57 | port2Num = port2IdToken[1] |
| 58 | |
| 59 | # Lets make sure the Devices are the same - otherwise its an error - Xconnect must be on same device |
| 60 | |
| 61 | if (port1Devicename != port2Devicename): |
| 62 | Exception("XConnect Device must be the same. D1= % D2=%" % (port1Devicename, port2Devicename)) |
| 63 | |
| 64 | # Get URL from PwaaS Ojbect |
| 65 | restCtrlUrl = pseudowireservice.networkControllerUrl |
| 66 | |
| 67 | data = { |
| 68 | port2Devicename : [ |
| 69 | { |
| 70 | "vlan" : vlanid, |
| 71 | "ports" : [port1Num, port2Num], |
| 72 | "name" : pseudowirename |
| 73 | } |
| 74 | ] |
| 75 | } |
| 76 | |
| 77 | headers = {'Content-Type': 'application/json'} |
| 78 | |
| 79 | resp = requests.post('{}/v1/network/configuration/apps/org.onosproject.segmentrouting/xconnect'.format(restCtrlUrl), |
| 80 | data=json.dumps(data), headers=headers, auth=HTTPBasicAuth('karaf', 'karaf')) |
| 81 | |
| 82 | if resp.status_code == 200: |
| 83 | logger.info("SegmentRoutingXConnect create successful") |
| 84 | return pseudowirename |
| 85 | else: |
| 86 | Exception("Pseudowire create failed Error Code: %s" % resp.status_code) |
| 87 | |
| 88 | |
| 89 | # Method to support connect |
| 90 | # |
| 91 | def connect(self, handle): |
| 92 | # Connect method - this is a no-op for this module, it does not support a complext state machine |
| 93 | logger.info("SegmentRoutingXConnect Pseudowire connect called, handle = %s" % handle) |
| 94 | |
| 95 | # Method to support disconnect connect |
| 96 | # |
| 97 | def disconnect(self, handle): |
| 98 | # Disconnect method - impl is TBD |
| 99 | logger.info("SegmentRoutingXConnect Pseudowire disconnect called, handle = %s" % handle) |
| 100 | |
| 101 | # Example command line syntax: |
| 102 | # curl --user onos:rocks -X DELETE http://138.120.151.126:8181/onos/v1/network/configuration/apps/org.onosproject.segmentrouting/xconnect |
| 103 | |
| 104 | # Method to support deletion |
| 105 | # |
| 106 | def delete(self, handle): |
| 107 | # Delete method - impl is TBD |
| 108 | logger.info("SegmentRoutingXConnect Pseudowire delete called, handle = %s" % handle) |
| 109 | |
| 110 | |