From ed73dbf357aff41edcbab401a94e5fbc266d9391 Mon Sep 17 00:00:00 2001 From: Mufaddal Makati Date: Fri, 7 Aug 2015 13:09:49 -0700 Subject: First Commit --- uni/pom.xml | 23 ++ uni/unibase/pom.xml | 23 ++ .../vcpe/uni/unibase/client/EvcPathClient.java | 180 +++++++++++++++ .../vcpe/uni/unibase/client/UniClient.java | 188 ++++++++++++++++ .../cablelabs/vcpe/uni/unibase/model/EvcPath.java | 112 ++++++++++ .../com/cablelabs/vcpe/uni/unibase/model/Uni.java | 230 +++++++++++++++++++ .../vcpe/uni/unibase/client/UniClientTest.java | 50 +++++ .../vcpe/uni/unibase/client/EvcPathClient$1.class | Bin 0 -> 776 bytes .../vcpe/uni/unibase/client/EvcPathClient.class | Bin 0 -> 5305 bytes .../vcpe/uni/unibase/client/UniClient$1.class | Bin 0 -> 748 bytes .../vcpe/uni/unibase/client/UniClient.class | Bin 0 -> 5328 bytes .../cablelabs/vcpe/uni/unibase/model/EvcPath.class | Bin 0 -> 3301 bytes .../cablelabs/vcpe/uni/unibase/model/Uni$1.class | Bin 0 -> 1000 bytes .../vcpe/uni/unibase/model/Uni$MacLayer.class | Bin 0 -> 1433 bytes .../vcpe/uni/unibase/model/Uni$PhysMedium.class | Bin 0 -> 1680 bytes .../vcpe/uni/unibase/model/Uni$SvcSpeed.class | Bin 0 -> 1641 bytes .../vcpe/uni/unibase/model/Uni$SyncMode.class | Bin 0 -> 1501 bytes .../vcpe/uni/unibase/model/Uni$Type.class | Bin 0 -> 1381 bytes .../com/cablelabs/vcpe/uni/unibase/model/Uni.class | Bin 0 -> 8039 bytes uni/unibase/target/maven-archiver/pom.properties | 5 + .../vcpe/uni/unibase/client/UniClientTest.class | Bin 0 -> 2949 bytes uni/unibase/target/unibase.jar | Bin 0 -> 18351 bytes uni/unimgr/dbg.js | 84 +++++++ uni/unimgr/package.json | 10 + uni/unimgr/uniMgrEmu.js | 247 +++++++++++++++++++++ 25 files changed, 1152 insertions(+) create mode 100644 uni/pom.xml create mode 100644 uni/unibase/pom.xml create mode 100644 uni/unibase/src/main/java/com/cablelabs/vcpe/uni/unibase/client/EvcPathClient.java create mode 100644 uni/unibase/src/main/java/com/cablelabs/vcpe/uni/unibase/client/UniClient.java create mode 100644 uni/unibase/src/main/java/com/cablelabs/vcpe/uni/unibase/model/EvcPath.java create mode 100644 uni/unibase/src/main/java/com/cablelabs/vcpe/uni/unibase/model/Uni.java create mode 100644 uni/unibase/src/test/java/com/cablelabs/vcpe/uni/unibase/client/UniClientTest.java create mode 100644 uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/client/EvcPathClient$1.class create mode 100644 uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/client/EvcPathClient.class create mode 100644 uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/client/UniClient$1.class create mode 100644 uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/client/UniClient.class create mode 100644 uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/EvcPath.class create mode 100644 uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$1.class create mode 100644 uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$MacLayer.class create mode 100644 uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$PhysMedium.class create mode 100644 uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$SvcSpeed.class create mode 100644 uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$SyncMode.class create mode 100644 uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$Type.class create mode 100644 uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni.class create mode 100644 uni/unibase/target/maven-archiver/pom.properties create mode 100644 uni/unibase/target/test-classes/com/cablelabs/vcpe/uni/unibase/client/UniClientTest.class create mode 100644 uni/unibase/target/unibase.jar create mode 100644 uni/unimgr/dbg.js create mode 100644 uni/unimgr/package.json create mode 100644 uni/unimgr/uniMgrEmu.js (limited to 'uni') diff --git a/uni/pom.xml b/uni/pom.xml new file mode 100644 index 0000000..a9d9fd2 --- /dev/null +++ b/uni/pom.xml @@ -0,0 +1,23 @@ + + + + com.cablelabs.vcpe + vcpe-services + 1.0-SNAPSHOT + + + 4.0.0 + + com.cablelabs.vcpe + uni + pom + 1.0-SNAPSHOT + + + unibase + + + + + diff --git a/uni/unibase/pom.xml b/uni/unibase/pom.xml new file mode 100644 index 0000000..839f4ad --- /dev/null +++ b/uni/unibase/pom.xml @@ -0,0 +1,23 @@ + + + + com.cablelabs.vcpe + uni + 1.0-SNAPSHOT + + + 4.0.0 + + com.cablelabs.vcpe + unibase + jar + 1.0-SNAPSHOT + + + unibase + + + + + diff --git a/uni/unibase/src/main/java/com/cablelabs/vcpe/uni/unibase/client/EvcPathClient.java b/uni/unibase/src/main/java/com/cablelabs/vcpe/uni/unibase/client/EvcPathClient.java new file mode 100644 index 0000000..1bc41b5 --- /dev/null +++ b/uni/unibase/src/main/java/com/cablelabs/vcpe/uni/unibase/client/EvcPathClient.java @@ -0,0 +1,180 @@ +package com.cablelabs.vcpe.uni.unibase.client; + +import com.cablelabs.vcpe.common.Dbg; +import com.cablelabs.vcpe.uni.unibase.model.EvcPath; +import com.cablelabs.vcpe.uni.unibase.model.Uni; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.GenericType; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.xml.bind.DatatypeConverter; +import java.util.List; + +/** + * Created by steve on 5/28/15. + */ + +public class EvcPathClient { + + private String evcMgrServer = "localhost"; + private String evcMgrPort = "8181"; + private String evcMgrCfgRESTPath = "/restconf/config/cl-vcpe-mef:evcs/"; + + private Client client; // provided by Jersey + + public EvcPathClient() { + client = ClientBuilder.newClient(); + } + + //-------------------------------------------------------- + public Response create(EvcPath evcPath ) + //-------------------------------------------------------- + { + WebTarget target =client.target("http://"+evcMgrServer+":" + evcMgrPort + evcMgrCfgRESTPath); + + String json = evcPath.toJson(); + Dbg.p("\nEVC Create JSON:"); + Dbg.p(json); + + Response response = target.path("evc") + .request(MediaType.APPLICATION_JSON) + .post(Entity.entity(json, MediaType.APPLICATION_JSON)); + + if (response.getStatus() != 200 ) // figure out how to use Status.OK + { + // in production you can be more specific based on reponse code, id, etc + throw new RuntimeException(response.getStatus() + ": there was an error on the server."); + } + //return response.readEntity(EvcPath.class); + return response; + } + + //-------------------------------------------------------- + public Response update(EvcPath evcPath) throws Exception + //-------------------------------------------------------- + { + WebTarget target =client.target("http://"+evcMgrServer+":" + evcMgrPort + evcMgrCfgRESTPath); + + String json = evcPath.toJson(); + String unamepass = "admin:admin"; + String authorizationHeaderValue = "Basic " + DatatypeConverter.printBase64Binary(unamepass.getBytes("UTF-8")); + Dbg.p("\nEVC Create/Update JSON:"); + Dbg.p(json); + + Response response = target.path("evc/"+evcPath.getId()) + .request(MediaType.APPLICATION_JSON) + .header("Authorization", authorizationHeaderValue) + .put(Entity.entity(json, MediaType.APPLICATION_JSON)); + + if (response.getStatus() != 200 ) // figure out how to use Status.OK + { + // in production you can be more specific based on reponse code, id, etc + throw new RuntimeException(response.getStatus() + ": there was an error on the server."); + } + return response; + } + //-------------------------------------------------------- + public void delete(String evcPathId) throws Exception + //-------------------------------------------------------- + // delete EvcPath of specified ID + { + WebTarget target =client.target("http://"+evcMgrServer+":" + evcMgrPort + evcMgrCfgRESTPath); + + String uNameAndPass = "admin:admin"; + String authorizationHeaderValue = "Basic " + + DatatypeConverter.printBase64Binary(uNameAndPass.getBytes("UTF-8")); + + Response response = target.path("evc/" + evcPathId) + .request(MediaType.APPLICATION_JSON) + .header("Authorization", authorizationHeaderValue) + .delete(); + if (response.getStatus() != 200) // figure out how to use Status.OK + { + // in production you can be more specific based on reponse code, id, etc + throw new RuntimeException(response.getStatus() + ": there was an error on the server."); + } + } + + // + // Code from here below requires work in order to work with ODL + // + + //-------------------------------------------------------- + public EvcPath get(String evcPathId) + //-------------------------------------------------------- + // get EvcPath of specified ID + { + WebTarget target = client.target("http://localhost:9090/evcmgr/webapi/"); + + Response response = target.path("evc/"+evcPathId).request(MediaType.APPLICATION_JSON).get(Response.class); + if (response.getStatus() != 200) // figure out how to use Status.OK + { + // in production you can be more specific based on reponse code, id, etc + throw new RuntimeException(response.getStatus() + ": there was an error on the server."); + } + + return response.readEntity(EvcPath.class); + } + + //-------------------------------------------------------- + public List getAll() + //-------------------------------------------------------- + // get a list of all EvcPath instances + { + + WebTarget target = client.target("http://localhost:9090/evcmgr/webapi/"); + + // Can I do this with a Response, so that I can check for errors + List response = target.path("evc/list") + .request(MediaType.APPLICATION_JSON) + .get(new GenericType>() { + }); + if (response == null) // figure out how to use Status.OK + { + // in production you can be more specific based on reponse code, id, etc + throw new RuntimeException("there was an error on the server."); + } + return response; + } + + //-------------------------------------------------------- + public EvcPath testGet() + //-------------------------------------------------------- + // test marshaling of EvcPath class from server json + { + WebTarget target = client.target("http://localhost:9090/evcmgr/webapi/"); + + Response response = target.path("evc").request(MediaType.APPLICATION_JSON).get(Response.class); + if (response.getStatus() != 200) // figure out how to use Status.OK + { + // in production you can be more specific based on reponse code, id, etc + throw new RuntimeException(response.getStatus() + ": there was an error on the server."); + } + + //return response; + return response.readEntity(EvcPath.class); + } + + //-------------------------------------------------------- + public String ping() + //-------------------------------------------------------- + // test connectivity + { + + WebTarget target = client.target("http://localhost:9090/evcmgr/webapi/"); + + Response response = target.path("evc").request(MediaType.TEXT_PLAIN).get(); + if (response.getStatus() != 200) // figure out how to use Status.OK + { + // in production you can be more specific based on reponse code, id, etc + throw new RuntimeException(response.getStatus() + ": there was an error on the server."); + } + + + return response.readEntity(String.class); + } +} diff --git a/uni/unibase/src/main/java/com/cablelabs/vcpe/uni/unibase/client/UniClient.java b/uni/unibase/src/main/java/com/cablelabs/vcpe/uni/unibase/client/UniClient.java new file mode 100644 index 0000000..a1dcff4 --- /dev/null +++ b/uni/unibase/src/main/java/com/cablelabs/vcpe/uni/unibase/client/UniClient.java @@ -0,0 +1,188 @@ +package com.cablelabs.vcpe.uni.unibase.client; + +import com.cablelabs.vcpe.common.Dbg; +import com.cablelabs.vcpe.uni.unibase.model.Uni; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.GenericType; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.List; +import javax.xml.bind.DatatypeConverter; + +/** + * Created by steve on 5/28/15. + */ + +public class UniClient { + + private String uniMgrServer = "localhost"; + private String uniMgrPort = "8181"; + private String uniMgrCfgRESTPath = "/restconf/config/cl-vcpe-mef:unis/"; + + private Client client; // provided by Jersey + + public UniClient() { + client = ClientBuilder.newClient(); + } + + //-------------------------------------------------------- + public Response create(Uni uni ) throws Exception + //-------------------------------------------------------- + // create Uni + { + WebTarget target =client.target("http://"+uniMgrServer+":" + uniMgrPort + uniMgrCfgRESTPath); + + String json = uni.toJson(); + Dbg.p("\nUNI Create JSON:"); + Dbg.p(json); + + String uNameAndPass = "admin:admin"; + String authorizationHeaderValue = "Basic " + + DatatypeConverter.printBase64Binary(uNameAndPass.getBytes("UTF-8")); + Response response = target.path("uni") + .request(MediaType.APPLICATION_JSON) + .header("Authorization", authorizationHeaderValue) + .post(Entity.entity(json, MediaType.APPLICATION_JSON)); + + if (response.getStatus() != 200 ) // figure out how to use Status.OK + { + // in production you can be more specific based on reponse code, id, etc + throw new RuntimeException(response.getStatus() + ": there was an error on the server."); + } + //return response.readEntity(Uni.class); + return response; + } + + //-------------------------------------------------------- + public Response update(Uni uni) throws Exception + //-------------------------------------------------------- + // create/update Uni. This seems to be how OLD expects uni creation + { + WebTarget target =client.target("http://"+uniMgrServer+":" + uniMgrPort + uniMgrCfgRESTPath); + + String json = uni.toJson(); + Dbg.p("\nUNI Create/Update JSON:"); + Dbg.p(json); + + String uNameAndPass = "admin:admin"; + String authorizationHeaderValue = "Basic " + + DatatypeConverter.printBase64Binary(uNameAndPass.getBytes("UTF-8")); + Response response = target.path("uni/"+uni.getId()) + .request(MediaType.APPLICATION_JSON) + .header("Authorization", authorizationHeaderValue) + .put(Entity.entity(json, MediaType.APPLICATION_JSON)); + + if (response.getStatus() != 200 ) // figure out how to use Status.OK + { + // in production you can be more specific based on reponse code, id, etc + throw new RuntimeException(response.getStatus() + ": there was an error on the server."); + } + return response; + } + + //-------------------------------------------------------- + public void delete(String uniId) throws Exception + //-------------------------------------------------------- + // delete Uni of specified ID + { + WebTarget target =client.target("http://"+uniMgrServer+":" + uniMgrPort + uniMgrCfgRESTPath); + + String uNameAndPass = "admin:admin"; + String authorizationHeaderValue = "Basic " + + DatatypeConverter.printBase64Binary(uNameAndPass.getBytes("UTF-8")); + + Response response = target.path("uni/" + uniId) + .request(MediaType.APPLICATION_JSON) + .header("Authorization", authorizationHeaderValue) + .delete(); + if (response.getStatus() != 200) // figure out how to use Status.OK + { + // in production you can be more specific based on reponse code, id, etc + throw new RuntimeException(response.getStatus() + ": there was an error on the server."); + } + } + + // + // Code from here below requires work in order to work with ODL + // + + //-------------------------------------------------------- + public Uni get(String uniId) + //-------------------------------------------------------- + // get Uni of specified ID + { + WebTarget target = client.target("http://localhost:9090/unimgr/webapi/"); + + Response response = target.path("uni/"+uniId).request(MediaType.APPLICATION_JSON).get(Response.class); + if (response.getStatus() != 200) // figure out how to use Status.OK + { + // in production you can be more specific based on reponse code, id, etc + throw new RuntimeException(response.getStatus() + ": there was an error on the server."); + } + + //return response; + return response.readEntity(Uni.class); + } + + //-------------------------------------------------------- + public List getAll() + //-------------------------------------------------------- + // get a list of all Uni instances + { + + WebTarget target = client.target("http://localhost:9090/unimgr/webapi/"); + + // Can I do this with a Response, so that I can check for errors + List response = target.path("uni/list") + .request(MediaType.APPLICATION_JSON) + .get(new GenericType>() { + }); + if (response == null) // figure out how to use Status.OK + { + // in production you can be more specific based on reponse code, id, etc + throw new RuntimeException("there was an error on the server."); + } + return response; + } + + //-------------------------------------------------------- + public Uni testGet() + //-------------------------------------------------------- + // test marshaling of Uni class from server json + { + WebTarget target = client.target("http://localhost:9090/unimgr/webapi/"); + + Response response = target.path("uni").request(MediaType.APPLICATION_JSON).get(Response.class); + if (response.getStatus() != 200) // figure out how to use Status.OK + { + // in production you can be more specific based on reponse code, id, etc + throw new RuntimeException(response.getStatus() + ": there was an error on the server."); + } + + //return response; + return response.readEntity(Uni.class); + } + + //-------------------------------------------------------- + public String ping() + //-------------------------------------------------------- + // test connectivity + { + + WebTarget target = client.target("http://localhost:9090/unimgr/webapi/"); + + Response response = target.path("uni").request(MediaType.TEXT_PLAIN).get(); + if (response.getStatus() != 200) // figure out how to use Status.OK + { + // in production you can be more specific based on reponse code, id, etc + throw new RuntimeException(response.getStatus() + ": there was an error on the server."); + } + + + return response.readEntity(String.class); + } +} diff --git a/uni/unibase/src/main/java/com/cablelabs/vcpe/uni/unibase/model/EvcPath.java b/uni/unibase/src/main/java/com/cablelabs/vcpe/uni/unibase/model/EvcPath.java new file mode 100644 index 0000000..6556fbb --- /dev/null +++ b/uni/unibase/src/main/java/com/cablelabs/vcpe/uni/unibase/model/EvcPath.java @@ -0,0 +1,112 @@ +package com.cablelabs.vcpe.uni.unibase.model; + +/** + * Created by steve on 7/24/15. + */ +public class EvcPath { + + String id = "unset"; + Uni uni1 = null; + Uni uni2 = null; + String cos; + Uni.SvcSpeed ingressBW = Uni.SvcSpeed.UNASSIGNED; + Uni.SvcSpeed egressBW = Uni.SvcSpeed.UNASSIGNED; + + public EvcPath(String id, Uni uni1, Uni uni2, + Uni.SvcSpeed ingressBW, + Uni.SvcSpeed egressBW, + String cos) + { + this.id = id; + this.uni1 = uni1; + this.uni2 = uni2; + this.cos = cos; + this.ingressBW = ingressBW; + this.egressBW = egressBW; + } + + public String toJson() { + +//{ +// "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": {} +// } +// } +//} + + String json = "{\n"+ + " \"evc\":\n"+ + " {\n"+ + " \"evc:id\": \""+ this.getId() +"\",\n"+ + " \"evc:uni-dest\":\n"+ + " [\n"+ + " {\n"+ + " \"order\": 0,\n"+ + " \"uni\": \""+ this.uni1.getId() +"\"\n"+ + " }\n"+ + " ],\n"+ + " \"evc:uni-source\":\n"+ + " [\n"+ + " {\n"+ + " \"order\": 0,\n"+ + " \"uni\": \""+ this.uni2.getId() +"\"\n"+ + " }\n"+ + " ],\n"+ + " \"evc:cos-id\": \""+ this.getCos() +"\",\n"+ + " \"evc:ingress-bw\":\n"+ + " {\n"+ +// " \"speed-1G\": {}\n"+ + " \"" + this.getIngressBW() + "\": {}\n"+ + " },\n"+ + " \"evc:egress-bw\":\n"+ + " {\n"+ +// " \"speed-1G\": {}\n"+ + " \"" + this.getEgressBW() + "\": {}\n"+ + " }\n"+ + " }\n"+ + "}"; + return json; + } + + + public String getId() { return id; } + public void setId(String id) { this.id = id; } + + public Uni getUn1() { return uni1; } + public void setUn1(Uni uni1) { this.uni1 = uni1; } + + public Uni getUn2() { return uni2; } + public void setUn2(Uni uni2) { this.uni2 = uni2; } + + public String getCos() { return cos; } + public void setCos(String cos) { this.cos = cos; } + + public Uni.SvcSpeed getIngressBW() { return ingressBW; } + public void setIngressBW(Uni.SvcSpeed ingressBW) { this.ingressBW = ingressBW; } + + public Uni.SvcSpeed getEgressBW() { return egressBW; } + public void setEgressBW(Uni.SvcSpeed egressBW) { this.egressBW = egressBW; } +} diff --git a/uni/unibase/src/main/java/com/cablelabs/vcpe/uni/unibase/model/Uni.java b/uni/unibase/src/main/java/com/cablelabs/vcpe/uni/unibase/model/Uni.java new file mode 100644 index 0000000..6d1b9c0 --- /dev/null +++ b/uni/unibase/src/main/java/com/cablelabs/vcpe/uni/unibase/model/Uni.java @@ -0,0 +1,230 @@ +package com.cablelabs.vcpe.uni.unibase.model; + +import com.cablelabs.vcpe.common.Dbg; + +import javax.xml.bind.annotation.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Created by steve on 5/24/15. + */ + +@XmlRootElement +public class Uni +{ + + public enum SvcSpeed { + UNASSIGNED ("UNASSIGNED"), + TEN_MEG ("speed-10M"), + HUNDRED_MEG ("speed-100M"), + ONE_GIG ("speed-1G"), + TEN_GIG ("speed-10G"); + private final String s; + private SvcSpeed(final String s) {this.s = s;} + @Override public String toString() { return s; } + } + + public enum PhysMedium { // just a sampling of 802.3 phys layers + UNASSIGNED ("UNASSIGNED"), + TEN_BASE_T ("10BASE‑T"), + HUNDERED_BASE_T("100BASE‑T"), + GIG_BASE_T ("1000BASE‑T"), + TEN_GIG_BASE_T ("10GBASE‑T"); + private final String s; + private PhysMedium(final String s) {this.s = s;} + @Override public String toString() { return s; } + } + + public enum MacLayer { + UNASSIGNED ("UNASSIGNED"), + IEEE_802_3 ("IEEE 802.3-2005"); + private final String s; + private MacLayer(final String s) {this.s = s;} + @Override public String toString() { return s; } + } + + public enum SyncMode { + UNASSIGNED ("UNASSIGNED"), + ENABLED ("syncEnabled"), + DISABLED ("syncDisabled"); + private final String s; + private SyncMode(final String s) {this.s = s;} + @Override public String toString() { return s; } + } + + public enum Type { // not sure what this is + UNASSIGNED ("UNASSIGNED"), + UNITYPE ("UNITYPE"); + private final String s; + private Type(final String s) {this.s = s;} + @Override public String toString() { return s; } + } + + @XmlElement(name="id") + private String id; + + @XmlTransient // This does not get written to JSON body + private SvcSpeed speed; + + @XmlElement(name="ip-address") + private String ipAddress; + + @XmlElement(name="mac-address") + private String macAddress; + + @XmlElement(name="physical-medium") + private PhysMedium physicalMedium; + + @XmlElement(name="mac-layer") + private MacLayer macLayer; + + @XmlElement(name="mode") + private SyncMode mode; + + @XmlElement(name="type") + private Type type; + + @XmlElement(name="mtu-size") + private long mtuSize; + + // no argument constructor required for JAX-RS + public Uni() { + this.id = "unset"; + this.speed = SvcSpeed.UNASSIGNED; + this.ipAddress = "unset"; + this.macAddress = "unset"; + this.physicalMedium = PhysMedium.UNASSIGNED; + this.macLayer = MacLayer.UNASSIGNED; + this.mode = SyncMode.UNASSIGNED; + this.type = Type.UNASSIGNED; + this.mtuSize = -1; + } + + public void setAllProps (String id, SvcSpeed speed, String ipAddress, + String macAddress, PhysMedium physicalMedium, + MacLayer macLayer, SyncMode mode, Type type, long mtuSize) { + this.id = id; + this.speed = speed; + this.ipAddress = ipAddress; + this.macAddress = macAddress; + this.physicalMedium = physicalMedium; + this.macLayer = macLayer; + this.mode = mode; + this.type = type; + this.mtuSize = mtuSize; + } + + public void dump() { dump(0); } + public void dump(int tab) { + Dbg.p(tab, "id: " + this.id); + Dbg.p(tab, "speed: " + this.speed); + Dbg.p(tab, "ipAddress: " + this.ipAddress); + Dbg.p(tab, "macAddress: " + this.macAddress); + Dbg.p(tab, "physicalMedium: " + this.physicalMedium); + Dbg.p(tab, "macLayer: " + this.macLayer); + Dbg.p(tab, "mode: " + this.mode); + Dbg.p(tab, "type: " + this.type); + Dbg.p(tab, "mtuSize: " + this.mtuSize); + } + + public String toJson() { + + String json = "{\n"+ + " \"uni\":\n"+ + " {\n"+ + " \"uni:id\": \""+ this.getId() +"\",\n"+ + " \"speed\":\n" + + " {\n" + + " \"" + this.getSpeed() + "\": "+"\"1\"\n"+ + " },\n"+ + " \"uni:mac-layer\": \""+ this.getMacLayer() +"\",\n"+ + " \"uni:physical-medium\": \""+ this.getPhysicalMedium() +"\",\n"+ + " \"uni:mtu-size\": \""+ this.getMtuSize() +"\",\n"+ + " \"uni:type\": \"\",\n"+ + " \"uni:mac-address\": \""+ this.getMacAddress() +"\",\n"+ + " \"uni:ip-address\": \""+ this.getIpAddress() +"\",\n"+ + " \"uni:mode\": \""+ this.getMode() +"\"\n"+ + " }\n"+ + "}"; + + return json; + } + + + public static SvcSpeed cirToSvcSpeed (long cir) { + + // find closest + SvcSpeed svcSpeed = SvcSpeed.UNASSIGNED; + if ( cir <= 10000 ) + svcSpeed = SvcSpeed.TEN_MEG; + else if ( cir <= 100000 ) + svcSpeed = SvcSpeed.HUNDRED_MEG; + else if ( cir <= 1000000 ) + svcSpeed = SvcSpeed.ONE_GIG; + else + svcSpeed = SvcSpeed.TEN_GIG; + + return svcSpeed; + } + + public static PhysMedium svcSpeedToPhysMedium (SvcSpeed svcSpeed) { + + + // just for demo, this really needs to come from host, when hosts are modeled + switch (svcSpeed) { + case TEN_MEG: + return PhysMedium.TEN_BASE_T; + case HUNDRED_MEG: + return PhysMedium.HUNDERED_BASE_T; + case ONE_GIG: + return PhysMedium.GIG_BASE_T; + case TEN_GIG: + return PhysMedium.TEN_GIG_BASE_T; + default: + return PhysMedium.UNASSIGNED; + } + } + + public static void dumpList(List uniList) { dumpList(0, uniList); } + public static void dumpList(int tab, List uniList) { + int numUni = 0; + Dbg.p("----- Uni List : [" + uniList.size() + "] elements"); + for (Uni curUni : uniList) { + numUni++; + Dbg.p(tab+1, ""); + curUni.dump(tab+2); + } + } + + // getters & setters + + public String getId() { return id; } + public void setId(String id) { this.id = id; } + + public SvcSpeed getSpeed() { return speed; } + public void setSpeed(SvcSpeed speed) { this.speed = speed; } + + public String getIpAddress() { return ipAddress; } + public void setIpAddress(String ipAddress) { this.ipAddress = ipAddress; } + + public String getMacAddress() { return macAddress; } + public void setMacAddress(String macAddress) { this.macAddress = macAddress; } + + public PhysMedium getPhysicalMedium() { return physicalMedium; } + public void setPhysicalMedium(PhysMedium physicalMedium) { this.physicalMedium = physicalMedium; } + + public MacLayer getMacLayer() { return macLayer; } + public void setMacLayer(MacLayer macLayer) { this.macLayer = macLayer; } + + public SyncMode getMode() { return mode; } + public void setMode(SyncMode mode) { this.mode = mode; } + + public Type getType() { return type; } + public void setType(Type type) { this.type = type; } + + public long getMtuSize() { return mtuSize; } + public void setMtuSize(long mtuSize) { this.mtuSize = mtuSize; } +} diff --git a/uni/unibase/src/test/java/com/cablelabs/vcpe/uni/unibase/client/UniClientTest.java b/uni/unibase/src/test/java/com/cablelabs/vcpe/uni/unibase/client/UniClientTest.java new file mode 100644 index 0000000..0160190 --- /dev/null +++ b/uni/unibase/src/test/java/com/cablelabs/vcpe/uni/unibase/client/UniClientTest.java @@ -0,0 +1,50 @@ +package com.cablelabs.vcpe.uni.unibase.client; + +import com.cablelabs.vcpe.uni.unibase.model.EvcPath; + +//import com.cablelabs.vcpe.cos.cosbase.client.CoSClient; +//import com.cablelabs.vcpe.cos.cosbase.model.CoS; + +import com.cablelabs.vcpe.uni.unibase.model.Uni; +import org.junit.Test; + +/** + * Created by steve on 5/28/15. + */ + +public class UniClientTest { + + @Test + public void testAll() throws Exception { + +// CoS gold = new CoS(); +// gold.setAllProps("gold", 100, 0.99, 17.43, 2.43, 0.01); + + + UniClient uniClient = new UniClient(); + + Uni uni1 = new Uni(); + uni1.setAllProps("uni-1", Uni.SvcSpeed.ONE_GIG, + "192.168.1.100", "11:AA:00:00:00:00", + Uni.PhysMedium.GIG_BASE_T, Uni.MacLayer.IEEE_802_3, + Uni.SyncMode.ENABLED, Uni.Type.UNITYPE, 1600); + uniClient.update(uni1); + + Uni uni2 = new Uni(); + uni2.setAllProps("uni-2", Uni.SvcSpeed.HUNDRED_MEG, + "192.168.1.101", "11:BB:00:00:00:00", + Uni.PhysMedium.HUNDERED_BASE_T, Uni.MacLayer.IEEE_802_3, + Uni.SyncMode.ENABLED, Uni.Type.UNITYPE, 1600); + + uniClient.update(uni1); + uniClient.update(uni2); + + + EvcPathClient evcPathClient = new EvcPathClient(); + EvcPath evcPath = new EvcPath( "new-evc", uni1, uni2, + Uni.SvcSpeed.ONE_GIG, + Uni.SvcSpeed.TEN_GIG, + "Gold" ); + evcPathClient.update(evcPath); + } +} \ No newline at end of file diff --git a/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/client/EvcPathClient$1.class b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/client/EvcPathClient$1.class new file mode 100644 index 0000000..a0424c4 Binary files /dev/null and b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/client/EvcPathClient$1.class differ diff --git a/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/client/EvcPathClient.class b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/client/EvcPathClient.class new file mode 100644 index 0000000..7a5d975 Binary files /dev/null and b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/client/EvcPathClient.class differ diff --git a/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/client/UniClient$1.class b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/client/UniClient$1.class new file mode 100644 index 0000000..c27fe95 Binary files /dev/null and b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/client/UniClient$1.class differ diff --git a/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/client/UniClient.class b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/client/UniClient.class new file mode 100644 index 0000000..2299402 Binary files /dev/null and b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/client/UniClient.class differ diff --git a/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/EvcPath.class b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/EvcPath.class new file mode 100644 index 0000000..665f9a9 Binary files /dev/null and b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/EvcPath.class differ diff --git a/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$1.class b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$1.class new file mode 100644 index 0000000..60bbc96 Binary files /dev/null and b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$1.class differ diff --git a/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$MacLayer.class b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$MacLayer.class new file mode 100644 index 0000000..a01569d Binary files /dev/null and b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$MacLayer.class differ diff --git a/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$PhysMedium.class b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$PhysMedium.class new file mode 100644 index 0000000..d1aafca Binary files /dev/null and b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$PhysMedium.class differ diff --git a/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$SvcSpeed.class b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$SvcSpeed.class new file mode 100644 index 0000000..ea1f246 Binary files /dev/null and b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$SvcSpeed.class differ diff --git a/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$SyncMode.class b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$SyncMode.class new file mode 100644 index 0000000..bd49b42 Binary files /dev/null and b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$SyncMode.class differ diff --git a/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$Type.class b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$Type.class new file mode 100644 index 0000000..bf73e35 Binary files /dev/null and b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni$Type.class differ diff --git a/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni.class b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni.class new file mode 100644 index 0000000..f982446 Binary files /dev/null and b/uni/unibase/target/classes/com/cablelabs/vcpe/uni/unibase/model/Uni.class differ diff --git a/uni/unibase/target/maven-archiver/pom.properties b/uni/unibase/target/maven-archiver/pom.properties new file mode 100644 index 0000000..84d59f2 --- /dev/null +++ b/uni/unibase/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Thu Aug 06 14:01:19 PDT 2015 +version=1.0-SNAPSHOT +groupId=com.cablelabs.vcpe +artifactId=unibase diff --git a/uni/unibase/target/test-classes/com/cablelabs/vcpe/uni/unibase/client/UniClientTest.class b/uni/unibase/target/test-classes/com/cablelabs/vcpe/uni/unibase/client/UniClientTest.class new file mode 100644 index 0000000..79bb6e4 Binary files /dev/null and b/uni/unibase/target/test-classes/com/cablelabs/vcpe/uni/unibase/client/UniClientTest.class differ diff --git a/uni/unibase/target/unibase.jar b/uni/unibase/target/unibase.jar new file mode 100644 index 0000000..46cc4d4 Binary files /dev/null and b/uni/unibase/target/unibase.jar differ 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); -- cgit 1.2.3-korg