aboutsummaryrefslogtreecommitdiffstats
path: root/uni/unimgr/uniMgrEmu.js
blob: dc9a8bfe894676ea63e05846c5fc55646b64f4f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*******************************************************************************
* Copyright (c) 2015 CableLabs Inc. and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution, and is available at
* http://www.apache.org/licenses/LICENSE-2.0
*******************************************************************************/


// 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);