Nokia: Putting in support for metro network services within XOS for E-CORD

Change-Id: I9277ccf808479dd593ee1b7b640a2247a5b28a39
diff --git a/views/ngXosViews/ecordTopology/mocks/data/SCA_ETH_FDFr_EC.json b/views/ngXosViews/ecordTopology/mocks/data/SCA_ETH_FDFr_EC.json
new file mode 100644
index 0000000..0637a08
--- /dev/null
+++ b/views/ngXosViews/ecordTopology/mocks/data/SCA_ETH_FDFr_EC.json
@@ -0,0 +1 @@
+[]
\ No newline at end of file
diff --git a/views/ngXosViews/ecordTopology/mocks/data/SCA_ETH_FPP_UNI_N.json b/views/ngXosViews/ecordTopology/mocks/data/SCA_ETH_FPP_UNI_N.json
new file mode 100644
index 0000000..6a0e547
--- /dev/null
+++ b/views/ngXosViews/ecordTopology/mocks/data/SCA_ETH_FPP_UNI_N.json
@@ -0,0 +1,80 @@
+[
+  {
+    "id": 3,
+    "interfaceCfgIdentifier": "uni3",
+    "transportPort": {
+        "Hostname": "Host1",
+        "Port": 1
+    },
+    "physicalLayer": "string",
+    "physicalLayerDuplexMode": "string",
+    "synchronousMode": "string",
+    "numberOfLinks": 0,
+    "uniResiliency": "string",
+    "frameFormat": "string",
+    "uniMaximumServiceFrameSize": 0,
+    "multiplexing": "string",
+    "uniCfgCeVidUntagged": 0,
+    "uniCfgCePriorityUntagged": 0,
+    "ceVlanId": "ceVlanId",
+    "evcId": "evcId",
+    "interfaceStatusMaxVc": 0,
+    "bundling": "string",
+    "allToOneBundling": "string",
+    "linkOam": "string",
+    "uniMeg": "string",
+    "eLMI": "string"
+  },
+  {
+    "id": 4,
+    "interfaceCfgIdentifier": "uni4",
+    "transportPort": {
+        "Hostname": "Host2",
+        "Port": 1
+    },
+    "physicalLayer": "string",
+    "physicalLayerDuplexMode": "string",
+    "synchronousMode": "string",
+    "numberOfLinks": 0,
+    "uniResiliency": "string",
+    "frameFormat": "string",
+    "uniMaximumServiceFrameSize": 0,
+    "multiplexing": "string",
+    "uniCfgCeVidUntagged": 0,
+    "uniCfgCePriorityUntagged": 0,
+    "ceVlanId": "ceVlanId",
+    "evcId": "evcId",
+    "interfaceStatusMaxVc": 0,
+    "bundling": "string",
+    "allToOneBundling": "string",
+    "linkOam": "string",
+    "uniMeg": "string",
+    "eLMI": "string"
+  },
+  {
+    "id": 5,
+    "interfaceCfgIdentifier": "uni5",
+    "transportPort": {
+        "Hostname": "Host3",
+        "Port": 1
+    },
+    "physicalLayer": "string",
+    "physicalLayerDuplexMode": "string",
+    "synchronousMode": "string",
+    "numberOfLinks": 0,
+    "uniResiliency": "string",
+    "frameFormat": "string",
+    "uniMaximumServiceFrameSize": 0,
+    "multiplexing": "string",
+    "uniCfgCeVidUntagged": 0,
+    "uniCfgCePriorityUntagged": 0,
+    "ceVlanId": "ceVlanId",
+    "evcId": "evcId",
+    "interfaceStatusMaxVc": 0,
+    "bundling": "string",
+    "allToOneBundling": "string",
+    "linkOam": "string",
+    "uniMeg": "string",
+    "eLMI": "string"
+  }
+]
diff --git a/views/ngXosViews/ecordTopology/mocks/ecord.conf.json b/views/ngXosViews/ecordTopology/mocks/ecord.conf.json
new file mode 100644
index 0000000..5f4d08b
--- /dev/null
+++ b/views/ngXosViews/ecordTopology/mocks/ecord.conf.json
@@ -0,0 +1,16 @@
+{
+  "endpoints": [
+    {
+      "url": "SCA_ETH_FPP_UNI_N",
+      "base": "onos/mef-sca-api/",
+      "methods": ["GET", "POST"],
+      "param": "interfaceCfgIdentifier"
+    },
+    {
+      "url": "SCA_ETH_FDFr_EC",
+      "base": "onos/mef-sca-api/",
+      "methods": ["GET", "POST"],
+      "param": "id"
+    }
+  ]
+}
\ No newline at end of file
diff --git a/views/ngXosViews/ecordTopology/mocks/sca.py b/views/ngXosViews/ecordTopology/mocks/sca.py
new file mode 100644
index 0000000..1b7aec3
--- /dev/null
+++ b/views/ngXosViews/ecordTopology/mocks/sca.py
@@ -0,0 +1,80 @@
+#!/usr/bin/python
+
+import copy
+import json
+from flask import Flask, make_response, request
+from flask.ext.cors import CORS
+from subprocess import call
+
+app = Flask(__name__)
+app.debug = True
+CORS(app)
+
+e_lines = {}
+
+
+@app.route('/SCA_ETH_FDFr_EC/findByState', methods=['GET'])
+def get_elines_by_state():
+    resp = make_response(json.dumps(e_lines.values()))
+    resp.mimetype = 'application/json'
+    resp.headers['Access-Control-Allow-Origin'] = '*'
+    return resp
+
+
+@app.route('/SCA_ETH_FDFr_EC', methods=['GET'])
+def get_elines():
+    resp = make_response(json.dumps(e_lines.values()))
+    resp.mimetype = 'application/json'
+    resp.headers['Access-Control-Allow-Origin'] = '*'
+    return resp
+
+
+@app.route('/SCA_ETH_FDFr_EC/<name>/', methods=['GET'])
+def get_eline(name):
+    resp = make_response(json.dumps(e_lines[int(name)]))
+    resp.mimetype = 'application/json'
+    resp.headers['Access-Control-Allow-Origin'] = '*'
+    return resp
+
+
+# Convert long value to dotted hex value with specified length in bytes
+def longToHex(l, length=6):
+    h = ("%x" % l)
+    if len(h) % 2 != 0:
+        h = '0' + h
+    result = ':'.join([h[i:i+2] for i in range(0, len(h), 2)])
+    prefix = '00:' * (length - (len(h) / 2) - (len(h) % 2))
+    return prefix + result
+
+
+@app.route('/SCA_ETH_FDFr_EC', methods=['POST'])
+def create_eline():
+    # Store E-Line
+    e_line = json.loads(request.data)
+    e_line['id'] = len(e_lines) + 1
+
+    e_lines[e_line['id']] = e_line
+
+    # Create E-Line in ONOS
+    flow_points = e_line['SCA_ETH_Flow_Points']
+
+    # src_host = flow_points[0]['scaEthFppUniN']['transportPort']['Hostname'] + '/-' + flow_points[0]['scaEthFppUniN']['transportPort']['Port']
+    # dst_host = flow_points[1]['scaEthFppUniN']['transportPort']['Hostname'] + '/-' + flow_points[1]['scaEthFppUniN']['transportPort']['Port']
+
+    src_index = int(flow_points[0]['scaEthFppUniN']['transportPort']['Hostname'][-2:])
+    dst_index = int(flow_points[1]['scaEthFppUniN']['transportPort']['Hostname'][-2:])
+
+    src_host = str(longToHex(src_index, 6)) + '/-1'
+    dst_host = str(longToHex(dst_index, 6)) + '/-1'
+
+    print 'Creating E-Line between %s (%s) and %s (%s)' % (src_index, src_host, dst_index, dst_host)
+    call(['onos', 'localhost', 'add-host-intent', src_host, dst_host])
+
+    # Return response
+    resp = make_response(json.dumps(e_line))
+    resp.mimetype = 'application/json'
+    resp.headers['Access-Control-Allow-Origin'] = '*'
+    return resp
+
+if __name__ == '__main__':
+    app.run(host='0.0.0.0', port=6000)