aboutsummaryrefslogtreecommitdiffstats
path: root/cos/cosbase/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'cos/cosbase/src/main/java/com')
-rw-r--r--cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/client/CoSClient.java151
-rw-r--r--cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/model/BandwidthProfile.java27
-rw-r--r--cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/model/CoS.java86
-rw-r--r--cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/repository/CoSRespository.java22
-rw-r--r--cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/repository/CoSRespositoryInMem.java74
5 files changed, 360 insertions, 0 deletions
diff --git a/cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/client/CoSClient.java b/cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/client/CoSClient.java
new file mode 100644
index 0000000..d47b11b
--- /dev/null
+++ b/cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/client/CoSClient.java
@@ -0,0 +1,151 @@
+package com.cablelabs.vcpe.cos.cosbase.client;
+
+import com.cablelabs.vcpe.cos.cosbase.model.CoS;
+
+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;
+
+/**
+ * Created by steve on 5/28/15.
+ */
+public class CoSClient {
+
+ private Client client; // provided by Jersey
+
+ public CoSClient() {
+ client = ClientBuilder.newClient();
+ }
+
+ //--------------------------------------------------------
+ public CoS create(CoS cos)
+ //--------------------------------------------------------
+ {
+ WebTarget target =client.target("http://localhost:9090/cosmgr/webapi/");
+ Response response = target.path("cos")
+ .request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(cos, 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(CoS.class);
+ }
+
+ //--------------------------------------------------------
+ public CoS update(CoS cos)
+ //--------------------------------------------------------
+ {
+ WebTarget target =client.target("http://localhost:9090/cosmgr/webapi/");
+ Response response = target.path("cos/"+cos.getId())
+ .request(MediaType.APPLICATION_JSON)
+ .put(Entity.entity(cos, 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(CoS.class);
+ }
+
+
+ //--------------------------------------------------------
+ public CoS get(String cosId)
+ //--------------------------------------------------------
+ // get CoS of specified ID
+ {
+ WebTarget target = client.target("http://localhost:9090/cosmgr/webapi/");
+
+ Response response = target.path("cos/"+cosId).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(CoS.class);
+ }
+
+ //--------------------------------------------------------
+ public List<CoS> getAll()
+ //--------------------------------------------------------
+ // get a list of all CoS instances
+ {
+
+ WebTarget target = client.target("http://localhost:9090/cosmgr/webapi/");
+
+ // Can I do this with a Response, so that I can check for errors
+ List<CoS> response = target.path("cos/list")
+ .request(MediaType.APPLICATION_JSON)
+ .get(new GenericType<List<CoS>>() {
+ });
+ 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 void delete(String cosId)
+ //--------------------------------------------------------
+ // delete CoS of specified ID
+ {
+ WebTarget target = client.target("http://localhost:9090/cosmgr/webapi/");
+ Response response = target.path("cos/"+cosId).request(MediaType.APPLICATION_JSON).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.");
+ }
+ }
+
+ //--------------------------------------------------------
+ public CoS testGet()
+ //--------------------------------------------------------
+ // test marshaling of CoS class from server json
+ {
+ WebTarget target = client.target("http://localhost:9090/cosmgr/webapi/");
+
+ Response response = target.path("cos").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(CoS.class);
+ }
+
+ //--------------------------------------------------------
+ public String ping()
+ //--------------------------------------------------------
+ // test connectivity
+ {
+
+ WebTarget target = client.target("http://localhost:9090/cosmgr/webapi/");
+
+ Response response = target.path("cos").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/cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/model/BandwidthProfile.java b/cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/model/BandwidthProfile.java
new file mode 100644
index 0000000..70f7313
--- /dev/null
+++ b/cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/model/BandwidthProfile.java
@@ -0,0 +1,27 @@
+package com.cablelabs.vcpe.cos.cosbase.model;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Created by steve on 5/24/15.
+ */
+
+@XmlRootElement
+public class BandwidthProfile {
+ private int committedInfoRate = 0; // MBS
+ private int committedBurtSize = 0; // MBS
+ private int excessInfoRate = 0; // MBS
+ private int excessBurstSize = 0; // MBS
+
+ public int getCommittedInfoRate() { return committedInfoRate; }
+ public void setCommittedInfoRate(int committedInfoRate) { this.committedInfoRate = committedInfoRate; }
+
+ public int getCommittedBurtSize() { return committedBurtSize; }
+ public void setCommittedBurtSize(int committedBurtSize) { this.committedBurtSize = committedBurtSize; }
+
+ public int getExcessInfoRate() { return excessInfoRate; }
+ public void setExcessInfoRate(int excessInfoRate) { this.excessInfoRate = excessInfoRate; }
+
+ public int getExcessBurstSize() { return excessBurstSize; }
+ public void setExcessBurstSize(int excessBurstSize) { this.excessBurstSize = excessBurstSize; }
+}
diff --git a/cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/model/CoS.java b/cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/model/CoS.java
new file mode 100644
index 0000000..8a4d219
--- /dev/null
+++ b/cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/model/CoS.java
@@ -0,0 +1,86 @@
+package com.cablelabs.vcpe.cos.cosbase.model;
+
+import com.cablelabs.vcpe.common.Dbg;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.List;
+
+/**
+ * Created by steve on 5/24/15.
+ */
+
+@XmlRootElement
+public class CoS
+{
+ private String id;
+
+ // private BandwidthProfile ingressBWProfile;
+ // private BandwidthProfile egressBWProfile;
+ // Above should be integrated at some point
+ // ... for now we will support commitedInfoRate in Lie of BW Profiles
+ private int commitedInfoRate; // MBPS
+
+ private double availbility; // percentage
+ private double frameDelay; // milli-seconds
+ private double jitter; // milli-seconds
+ private double frameLoss; // percentage
+
+ // no argument constructor required for JAX-RS
+ public CoS() {
+ commitedInfoRate = 0;
+ availbility = 0.0;
+ frameDelay = 0.0;
+ jitter = 0.0;
+ frameLoss = 0.0;
+ }
+
+
+ public String getId() { return id; }
+ public void setId(String id) { this.id = id; }
+
+ public int getCommitedInfoRate() { return commitedInfoRate; }
+ public void setCommitedInfoRate(int commitedInfoRate) { this.commitedInfoRate = commitedInfoRate; }
+
+ public double getAvailbility() { return availbility; }
+ public void setAvailbility(double availbility) { this.availbility = availbility; }
+
+ public double getFrameDelay() { return frameDelay; }
+ public void setFrameDelay(double frameDelay) { this.frameDelay = frameDelay; }
+
+ public double getJitter() { return jitter; }
+ public void setJitter(double jitter) { this.jitter = jitter; }
+
+ public double getFrameLoss() { return frameLoss; }
+ public void setFrameLoss(double frameLoss) { this.frameLoss = frameLoss; }
+
+ public void setAllProps(String id, int commitedInfoRate, double availbility, double frameDelay, double jitter, double frameLoss)
+ {
+ this.id = id;
+ this.commitedInfoRate = commitedInfoRate;
+ this.availbility = availbility;
+ this.frameDelay = frameDelay;
+ this.jitter = jitter;
+ this.frameLoss = frameLoss;
+ }
+
+ public void dump() { dump(0); }
+ public void dump(int tab) {
+ Dbg.p(tab, "id: " + this.id);
+ Dbg.p(tab, "commInfoRate: " + this.commitedInfoRate);
+ Dbg.p(tab, "availbility: " + this.availbility);
+ Dbg.p(tab, "frameDelay: " + this.frameDelay);
+ Dbg.p(tab, "jitter: " + this.jitter);
+ Dbg.p(tab, "frameLoss: " + this.frameLoss);
+ }
+
+ public static void dumpList(List<CoS> cosList) { dumpList(0, cosList); }
+ public static void dumpList(int tab, List<CoS> cosList) {
+ int numCos = 0;
+ Dbg.p("----- CoS List : [" + cosList.size() + "] elements");
+ for (CoS curCos : cosList) {
+ numCos++;
+ Dbg.p(tab+1, "<Entry " + numCos+">");
+ curCos.dump(tab+2);
+ }
+ }
+}
diff --git a/cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/repository/CoSRespository.java b/cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/repository/CoSRespository.java
new file mode 100644
index 0000000..3a58000
--- /dev/null
+++ b/cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/repository/CoSRespository.java
@@ -0,0 +1,22 @@
+package com.cablelabs.vcpe.cos.cosbase.repository;
+
+import com.cablelabs.vcpe.cos.cosbase.model.CoS;
+
+import java.util.List;
+
+/**
+ * Created by steve on 5/25/15.
+ */
+public interface CoSRespository
+{
+ // TODO add exceptions
+
+ CoS add(CoS cos); // returns null if already exists, otherwise returns stored cos
+ CoS get(String cosId); // returns null if not found, otherwise stored cos
+ CoS update(CoS cos); // returns null if did not exit, otherwise cos as it was previous to update (put in any case)
+ CoS delete(String cosId); // returns null if not found, otherwise cos as it was previous to delete
+ int count(); // number of CoS stored in the repo
+ List<CoS> getAll();
+
+ public void dump(int tab); // print out contents of the repo
+}
diff --git a/cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/repository/CoSRespositoryInMem.java b/cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/repository/CoSRespositoryInMem.java
new file mode 100644
index 0000000..2fa44c1
--- /dev/null
+++ b/cos/cosbase/src/main/java/com/cablelabs/vcpe/cos/cosbase/repository/CoSRespositoryInMem.java
@@ -0,0 +1,74 @@
+package com.cablelabs.vcpe.cos.cosbase.repository;
+
+import com.cablelabs.vcpe.common.Dbg;
+import com.cablelabs.vcpe.cos.cosbase.model.CoS;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Created by steve on 5/24/15.
+ */
+
+
+/*
+ Singleton that contains a hashmap which holds instances of CoS objects, indexed by CiS ID
+ */
+
+public enum CoSRespositoryInMem implements CoSRespository {
+ INSTANCE; // Singleton
+
+ private Map< String, CoS> cosDB = new ConcurrentHashMap<String, CoS>();
+
+ @Override
+ public CoS add(CoS cos) {
+ if ( this.get(cos.getId()) != null ) {
+ return null;
+ }
+ cosDB.put(cos.getId(), cos );
+ return cos;
+ }
+
+ @Override
+ public CoS get(String cosId) {
+ return cosDB.get(cosId);
+ }
+
+ @Override
+ public CoS update(CoS cos) {
+ // put returns null if cos did not exist, other returns cos as it stood prior to put
+ return cosDB.put(cos.getId(), cos);
+ }
+
+ @Override
+ public CoS delete(String cosId) {
+ // remove returns null if cos did not exist, other returns cos as it stood prior to remove
+ return cosDB.remove(cosId);
+ }
+
+ @Override
+ public List<CoS> getAll() {
+ List<CoS> cosList = new ArrayList<CoS>(cosDB.values());
+ return cosList;
+ }
+
+ @Override
+ public int count() {
+ return cosDB.size();
+ }
+
+ @Override
+ public void dump(int tab) {
+
+ Dbg.p(tab, "CoS Repo: " + cosDB.size() + " entrie(s)");
+ int numCos = 0;
+ for (CoS curCos : cosDB.values()) {
+ numCos++;
+ Dbg.p(tab+1, "<Entry " + numCos+">");
+ curCos.dump(tab+2);
+ }
+ }
+
+}