aboutsummaryrefslogtreecommitdiffstats
path: root/uni/unimgr
diff options
context:
space:
mode:
authorMufaddal Makati <mmakati@mmakatimbpr15.cablelabs.com>2015-08-07 13:09:49 -0700
committerMufaddal Makati <mmakati@mmakatimbpr15.cablelabs.com>2015-08-07 13:09:49 -0700
commited73dbf357aff41edcbab401a94e5fbc266d9391 (patch)
treee3561a9290e4bd0de19704228867ec91910e68ed /uni/unimgr
parentf44f4aa8b5eb244fc7603c17e875eebf0f3b0b67 (diff)
First Commit
Diffstat (limited to 'uni/unimgr')
-rw-r--r--uni/unimgr/dbg.js84
-rw-r--r--uni/unimgr/package.json10
-rw-r--r--uni/unimgr/uniMgrEmu.js247
3 files changed, 341 insertions, 0 deletions
diff --git a/uni/unimgr/dbg.js b/uni/unimgr/dbg.js
new file mode 100644
index 0000000..f4d3416
--- /dev/null
+++ b/uni/unimgr/dbg.js
@@ -0,0 +1,84 @@
+(function(){
+
+ var dbgFlag = true;
+ var pre = ""
+
+ var on = function() { dbgFlag = true; };
+ var off = function() { dbgFlag = false; };
+
+ var p = function(str, tab) {
+ if ( dbgFlag )
+ {
+ var tabStr = "";
+ if (tab) {
+ for (var i = 0; i < tab; i++ )
+ tabStr += " ";
+ }
+ console.log(pre + tabStr + str);
+ }
+ };
+
+ var pj = function(obj) {
+ if ( dbgFlag )
+ console.log(JSON.stringify(obj,null,3)) ;
+ };
+
+ var e = function(eMsg) {
+ console.log("!! ERROR: " + eMsg);
+ }
+
+ var w = function(eMsg) {
+ console.log("** WARNIING: " + eMsg);
+ }
+
+ // for testing. Write regaurdless of dbgFlag
+ var t = function(str, tab) {
+ var tabStr = "";
+ if (tab) {
+ for (var i = 0; i < tab; i++ )
+ tabStr += " ";
+ }
+ console.log(pre + tabStr + str);
+ }
+
+function curTime() {
+
+ var date = new Date();
+
+ var hour = date.getHours();
+ hour = (hour < 10 ? "0" : "") + hour;
+
+ var min = date.getMinutes();
+ min = (min < 10 ? "0" : "") + min;
+
+ var sec = date.getSeconds();
+ sec = (sec < 10 ? "0" : "") + sec;
+
+ // var year = date.getFullYear();
+
+ // var month = date.getMonth() + 1;
+ // month = (month < 10 ? "0" : "") + month;
+
+ // var day = date.getDate();
+ // day = (day < 10 ? "0" : "") + day;
+
+ // return year + ":" + month + ":" + day + ":" + hour + ":" + min + ":" + sec;
+
+ return hour + ":" + min + ":" + sec;
+
+
+}
+
+ module.exports.curTime = curTime; // returns str w current time
+
+ module.exports.on = on; // enable DBG printing
+ module.exports.off = off; // squelch DBG printing
+ module.exports.p = p; // print a debug string
+ module.exports.pj = pj; // print JSON version of an object
+ module.exports.w = w; // print an warning msg
+ module.exports.e = e; // print an error msg
+ module.exports.t = t; // print an error msg
+
+
+
+}()); \ No newline at end of file
diff --git a/uni/unimgr/package.json b/uni/unimgr/package.json
new file mode 100644
index 0000000..9c2c9f6
--- /dev/null
+++ b/uni/unimgr/package.json
@@ -0,0 +1,10 @@
+{
+ "name": "unimgr-emulator",
+ "version": "0.0.1",
+ "description": "recieves and prints unimgr REST calls",
+ "author": "steve@sentosatech.com",
+ "dependencies": {
+ "express" : "latest",
+ "body-parser": "*"
+ }
+} \ No newline at end of file
diff --git a/uni/unimgr/uniMgrEmu.js b/uni/unimgr/uniMgrEmu.js
new file mode 100644
index 0000000..f5ecb88
--- /dev/null
+++ b/uni/unimgr/uniMgrEmu.js
@@ -0,0 +1,247 @@
+
+// Create express HTTP server app
+var express = require('express');
+var app = express();
+
+// have express parse http request JSON bodies into POJO's
+var bodyParser = require('body-parser');
+app.use(bodyParser.json());
+
+// local modules
+var dbg = require('./dbg.js');
+
+// enable cross domain requests
+app.all('*', function(req, res, next) {
+ res.header("Access-Control-Allow-Origin", "*");
+ res.header("Access-Control-Allow-Headers", "X-Requested-With");
+ res.header('Access-Control-Allow-Headers', 'Content-Type');
+ res.header('Access-Control-Allow-Headers', 'Authorization');
+ res.header('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS');
+ next();
+});
+
+
+// ---------------------------------------------
+// UNI Manager Services
+// ---------------------------------------------
+// PUT: Create/update UNI
+// /restconf/config/cl-vcpe-mef:unis/uni/
+// BODY:
+// {
+// "uni": {
+// "uni:id": "822f7eec-2b35-11e5-b345-feff819cdc9f",
+// "speed": {
+// "speed-1G": 1
+// },
+// "uni:mac-layer": "IEEE 802.3-2005",
+// "uni:physical-medium": "UNI TypeFull Duplex 2 Physical Interface",
+// "uni:mtu-size": 0,
+// "uni:type": "",
+// "uni:mac-address": "68:5b:35:bb:f8:3e",
+// "uni:ip-address": "192.168.0.22",
+// "uni:mode": "Full Duplex"
+// }
+// }
+//
+// GET: Query UNI
+// /restconf/operational/cl-vcpe-mef:unis/uni/
+// RESPONSE:
+// {
+// "uni": [
+// {
+// "id": "822f7eec-2b35-11e5-b345-feff819cdc9f",
+// "type": "",
+// "speed": {
+// "speed-1G": [
+// null
+// ]
+// },
+// "ip-address": "192.168.1.30",
+// "physical-medium": "UNI TypeFull Duplex 2 Physical Interface",
+// "mode": "Full Duplex",
+// "mac-address": "08:00:27:35:64:90",
+// "mtu-size": 0,
+// "mac-layer": "IEEE 802.3-2005"
+// }
+// ]
+// }
+//
+//
+// DELETE: Delete a UNI
+// /restconf/config/cl-vcpe-mef:unis/uni/
+//
+// ---------------------------------------------
+
+
+var uniMgrOpPath = "/restconf/operational/cl-vcpe-mef:unis/uni/";
+var uniMgrOpId = uniMgrOpPath+":uniId"
+
+var uniMgrCfgPath = "/restconf/config/cl-vcpe-mef:unis/uni/";
+var uniMgrCfgId = uniMgrCfgPath+":uniId"
+
+dbg.p("uni Op REST path : " + uniMgrOpPath);
+dbg.p("uni Op REST id : " + uniMgrOpId);
+dbg.p("uni Cfg REST path : " + uniMgrCfgPath);
+dbg.p("uni Cfg REST id : " + uniMgrCfgId);
+
+
+// We will maintain a map of UNI's created
+var uniMap = {};
+
+
+var removeUniNameSpace = function(uniIn ) {
+ //dbg.p("in removeUniNameSpace()");
+ var uniOut = {};
+
+ // remove pesky ODL namespace qualifiers, as they are not present in ODL responses
+ uniOut["uni"] =
+ [
+ {
+ "id" : uniIn["uni"]["uni:id"],
+ "speed" : uniIn["uni"]["speed"],
+ "mac-layer" : uniIn["uni"]["uni:mac-layer"],
+ "physical-medium" : uniIn["uni"]["uni:physical-medium"],
+ "mtu-size" : uniIn["uni"]["uni:mtu-size"],
+ "type" : uniIn["uni"]["uni:type"],
+ "mac-address" : uniIn["uni"]["uni:mac-address"],
+ "ip-address" : uniIn["uni"]["uni:ip-address"],
+ "mode" : uniIn["uni"]["uni:mode"]
+ }
+ ]
+
+ // dbg.p("Clean uni"); dbg.pj(uniOut);
+ return uniOut;
+}
+
+// Create/update a UNI
+// ---------------------------------------------
+app.put( uniMgrCfgId, function(req, resp){
+ dbg.p ("... [" + dbg.curTime() + "] made it to PUT: " + uniMgrCfgPath + req.params.uniId );
+
+ var uni = req.body;
+ dbg.p("Creating /Updating Uni: ");
+ dbg.pj(uni);
+
+ uniClean = removeUniNameSpace(uni);
+ uniMap[uniClean.uni[0].id] = uniClean;
+
+ // dbg.p("uni map after push of clean"); dbg.pj(uniMap);
+ resp.send( { "message":
+ "... made it to PUT: " + uniMgrCfgId } );
+});
+
+
+
+// Query UNI Info
+// ---------------------------------------------
+app.get( uniMgrOpId, function(req, resp){
+
+ var uniId = req.params.uniId;
+ dbg.p ("... [" + dbg.curTime() + "] made it to GET: " + uniMgrOpPath + uniId );
+
+ var uniToReturn = null;
+ if ( uniMap[uniId] )
+ uniToReturn = uniMap[uniId];
+ else
+ uniToReturn = { "error" : "uni not in the DB: " + uniId }
+
+ resp.send( uniToReturn );
+});
+
+// Delete UNI
+// ---------------------------------------------
+app.delete( uniMgrCfgId, function(req, resp){
+ var uniId = req.params.uniId;
+ dbg.p ("... [" + dbg.curTime() + "] made it to DELETE: " + uniMgrCfgPath + uniId );
+
+ // dbg.p("uni map prior to delete");
+ // dbg.pj(uniMap);
+ delete uniMap[uniId];
+ // dbg.p("-----------------------------------");
+ // dbg.p("uni map after delete");
+ // dbg.pj(uniMap);
+
+ resp.send( { "message":
+ "... made it to DELETE: " + uniMgrCfgPath + uniId } );
+});
+
+// ---------------------------------------------
+// EVC Path Services
+// ---------------------------------------------
+// POST/PUT: Create/update UNI
+// /restconf/operational/cl-vcpe-mef:evcs/evc/
+// BODY:
+// {
+// "evc":
+// {
+// "evc:id": "822f8284-2b35-11e5-b345-feff819cdc9f",
+// "evc:uni-dest":
+// [
+// {
+// "order": 0,
+// "uni": "822f7eec-2b35-11e5-b345-feff819cdc9f"
+// }
+// ],
+// "evc:uni-source":
+// [
+// {
+// "order": 0,
+// "uni": "111f7eec-2c35-11e5-b345-feff819cdc9f"
+// }
+// ],
+// "evc:cos-id": "string",
+// "evc:ingress-bw":
+// {
+// "speed-1G": {}
+// },
+// "evc:egress-bw":
+// {
+// "speed-1G": {}
+// }
+// }
+// }
+//
+// ---------------------------------------------
+
+var evcMgrCfgPath = "/restconf/config/cl-vcpe-mef:evcs/evc/";
+var evcMgrCfgId = evcMgrCfgPath+":evcId"
+dbg.p("evc cfg REST path : " + evcMgrCfgPath);
+dbg.p("evc cfg REST id : " + evcMgrCfgId);
+
+// We will maintain a map of EVCs created
+var evcMap = {};
+
+
+// Create/update EVC Path
+// ---------------------------------------------
+app.put( evcMgrCfgId, function(req, resp){
+ var evcId = req.params.evcId;
+ dbg.p ("... [" + dbg.curTime() + "] made it to PUT: " + evcMgrCfgPath + evcId );
+ dbg.p("req body = ");
+ dbg.pj(req.body);
+ dbg.p("----------------------------------------------------")
+ resp.send( { "message":
+ "... made it to PUT: " + evcMgrCfgId } );
+});
+
+
+// Query EVC Info
+// ---------------------------------------------
+// TBD
+
+
+// Delete EVC
+// ---------------------------------------------
+app.delete( evcMgrCfgId, function(req, resp){
+ var evcId = req.params.evcId;
+ dbg.p ("... [" + dbg.curTime() + "] made it to DELETE: " + evcMgrCfgPath + evcId );
+
+ // currently not keeping a map of EVCs, just acknowledge recept of REST msg
+ resp.send( { "message":
+ "... made it to DELETE: " + evcMgrCfgPath + evcId } );
+});
+
+
+var PORT = 8181;
+app.listen(PORT);
+console.log('Running on http://localhost:' + PORT);