aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/core
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/core')
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java6
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java30
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ArpPaCriterion.java80
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java13
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instruction.java6
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java55
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/DeviceHighlight.java12
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/NodeBadge.java220
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/NodeHighlight.java27
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/TopoConstants.java3
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/TopoJson.java19
-rw-r--r--framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/NodeBadgeTest.java112
-rw-r--r--framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/TopoJsonTest.java46
13 files changed, 611 insertions, 18 deletions
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
index a628725c..6174cef6 100644
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
@@ -237,6 +237,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
case NOACTION:
case OUTPUT:
case GROUP:
+ case QUEUE:
case L0MODIFICATION:
case L2MODIFICATION:
case L3MODIFICATION:
@@ -381,6 +382,11 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
}
@Override
+ public Builder setQueue(long queueId) {
+ return add(Instructions.setQueue(queueId));
+ }
+
+ @Override
public TrafficTreatment.Builder meter(MeterId meterId) {
return add(Instructions.meterTraffic(meterId));
}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
index 33753afa..c7fe8b85 100644
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
@@ -190,14 +190,14 @@ public interface TrafficTreatment {
/**
* Push MPLS ether type.
*
- * @return a treatment builder.
+ * @return a treatment builder
*/
Builder pushMpls();
/**
* Pops MPLS ether type.
*
- * @return a treatment builder.
+ * @return a treatment builder
*/
Builder popMpls();
@@ -205,7 +205,7 @@ public interface TrafficTreatment {
* Pops MPLS ether type and set the new ethertype.
*
* @param etherType an ether type
- * @return a treatment builder.
+ * @return a treatment builder
* @deprecated in Drake Release
*/
@Deprecated
@@ -215,22 +215,22 @@ public interface TrafficTreatment {
* Pops MPLS ether type and set the new ethertype.
*
* @param etherType an ether type
- * @return a treatment builder.
+ * @return a treatment builder
*/
Builder popMpls(EthType etherType);
/**
* Sets the mpls label.
*
- * @param mplsLabel MPLS label.
- * @return a treatment builder.
+ * @param mplsLabel MPLS label
+ * @return a treatment builder
*/
Builder setMpls(MplsLabel mplsLabel);
/**
* Sets the mpls bottom-of-stack indicator bit.
*
- * @param mplsBos boolean to set BOS=1 (true) or BOS=0 (false).
+ * @param mplsBos boolean to set BOS=1 (true) or BOS=0 (false)
* @return a treatment builder.
*/
Builder setMplsBos(boolean mplsBos);
@@ -261,6 +261,14 @@ public interface TrafficTreatment {
Builder group(GroupId groupId);
/**
+ * Sets the Queue ID.
+ *
+ * @param queueId a queue ID
+ * @return a treatment builder
+ */
+ Builder setQueue(long queueId);
+
+ /**
* Sets a meter to be used by this flow.
*
* @param meterId a meter id
@@ -280,14 +288,14 @@ public interface TrafficTreatment {
/**
* Pops outermost VLAN tag.
*
- * @return a treatment builder.
+ * @return a treatment builder
*/
Builder popVlan();
/**
* Pushes a new VLAN tag.
*
- * @return a treatment builder.
+ * @return a treatment builder
*/
Builder pushVlan();
@@ -327,8 +335,8 @@ public interface TrafficTreatment {
/**
* Sets the tunnel id.
*
- * @param tunnelId a tunnel id.
- * @return a treatment builder.
+ * @param tunnelId a tunnel id
+ * @return a treatment builder
*/
Builder setTunnelId(long tunnelId);
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ArpPaCriterion.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ArpPaCriterion.java
new file mode 100644
index 00000000..ba5a03d8
--- /dev/null
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ArpPaCriterion.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.flow.criteria;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+import java.util.Objects;
+
+import org.onlab.packet.Ip4Address;
+
+/**
+ * Implementation of arp spa or tpa address criterion.
+ */
+public final class ArpPaCriterion implements Criterion {
+ private final Ip4Address ip;
+ private final Type type;
+
+ /**
+ * Constructor.
+ *
+ * @param ip the Ip4 Address to match.
+ * @param type the match type. Should be one of the following:
+ * Type.ARP_SPA, Type.ARP_TPA
+ */
+ ArpPaCriterion(Ip4Address ip, Type type) {
+ this.ip = ip;
+ this.type = type;
+ }
+
+ @Override
+ public Type type() {
+ return this.type;
+ }
+
+ /**
+ * Gets the Ip4 Address to match.
+ *
+ * @return the Ip4 Address to match
+ */
+ public Ip4Address ip() {
+ return this.ip;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(type().toString())
+ .add("ip", ip).toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(type().ordinal(), ip);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof ArpPaCriterion) {
+ ArpPaCriterion that = (ArpPaCriterion) obj;
+ return Objects.equals(ip, that.ip) &&
+ Objects.equals(type, that.type);
+ }
+ return false;
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java
index ae940bdc..778d50a5 100644
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java
@@ -16,6 +16,7 @@
package org.onosproject.net.flow.criteria;
import org.onlab.packet.EthType;
+import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
@@ -25,11 +26,11 @@ import org.onlab.packet.VlanId;
import org.onosproject.net.IndexedLambda;
import org.onosproject.net.Lambda;
import org.onosproject.net.OchSignal;
+import org.onosproject.net.OchSignalType;
import org.onosproject.net.OduSignalId;
import org.onosproject.net.OduSignalType;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.criteria.Criterion.Type;
-import org.onosproject.net.OchSignalType;
/**
* Factory class to create various traffic selection criteria.
@@ -508,6 +509,16 @@ public final class Criteria {
return new OduSignalTypeCriterion(signalType);
}
+ /**
+ * Creates a match on IPv4 source field using the specified value.
+ *
+ * @param ip ipv4 source value
+ * @return match criterion
+ */
+ public static Criterion matchArpTpa(Ip4Address ip) {
+ return new ArpPaCriterion(ip, Type.ARP_TPA);
+ }
+
public static Criterion dummy() {
return new DummyCriterion();
}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instruction.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instruction.java
index eddbbb71..2f6a1cc1 100644
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instruction.java
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instruction.java
@@ -49,6 +49,12 @@ public interface Instruction {
GROUP,
/**
+ * Signifies that the traffic should be enqueued to an already-configured
+ queue on a port.
+ */
+ QUEUE,
+
+ /**
* Signifies that traffic should be metered according to a meter.
*/
METER,
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
index 26981e5e..8868bf7c 100644
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
@@ -94,6 +94,17 @@ public final class Instructions {
return new GroupInstruction(groupId);
}
+ /**
+ * Creates a set-queue instruction.
+ *
+ * @param queueId Queue Id
+ * @return set-queue instruction
+ */
+ public static SetQueueInstruction setQueue(final long queueId) {
+ checkNotNull(queueId, "queue ID cannot be null");
+ return new SetQueueInstruction(queueId);
+ }
+
public static MeterInstruction meterTraffic(final MeterId meterId) {
checkNotNull(meterId, "meter id cannot be null");
return new MeterInstruction(meterId);
@@ -625,6 +636,50 @@ public final class Instructions {
}
/**
+ * Set-Queue Instruction.
+ */
+ public static final class SetQueueInstruction implements Instruction {
+ private final long queueId;
+
+ private SetQueueInstruction(long queueId) {
+ this.queueId = queueId;
+ }
+
+ public long queueId() {
+ return queueId;
+ }
+
+ @Override
+ public Type type() {
+ return Type.QUEUE;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(type().toString())
+ .add("queueId", queueId).toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(type().ordinal(), queueId);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof SetQueueInstruction) {
+ SetQueueInstruction that = (SetQueueInstruction) obj;
+ return Objects.equals(queueId, that.queueId);
+
+ }
+ return false;
+ }
+ }
+
+ /**
* A meter instruction.
*/
public static final class MeterInstruction implements Instruction {
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/DeviceHighlight.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/DeviceHighlight.java
index 0ce6592c..0cc15475 100644
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/DeviceHighlight.java
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/DeviceHighlight.java
@@ -17,16 +17,16 @@
package org.onosproject.ui.topo;
/**
- * Denotes the highlighting to apply to a device.
+ * Denotes the highlighting to be applied to a device.
*/
public class DeviceHighlight extends NodeHighlight {
+ /**
+ * Constructs a device highlight entity.
+ *
+ * @param deviceId the device identifier
+ */
public DeviceHighlight(String deviceId) {
super(TopoElementType.DEVICE, deviceId);
}
-
- // TODO: implement device highlighting:
- // - visual highlight
- // - badging
-
}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/NodeBadge.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/NodeBadge.java
new file mode 100644
index 00000000..7b517111
--- /dev/null
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/NodeBadge.java
@@ -0,0 +1,220 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.ui.topo;
+
+/**
+ * Designates a badge to be applied to a node in the topology view.
+ */
+public final class NodeBadge {
+
+ private static final String EMPTY = "";
+
+ /** Designates the badge status. */
+ public enum Status {
+ INFO("i"),
+ WARN("w"),
+ ERROR("e");
+
+ private String code;
+
+ Status(String code) {
+ this.code = code;
+ }
+
+ @Override
+ public String toString() {
+ return "{" + code + "}";
+ }
+
+ /** Returns the status code in string form. */
+ public String code() {
+ return code;
+ }
+ }
+
+ private final Status status;
+ private final boolean isGlyph;
+ private final String text;
+ private final String message;
+
+ // only instantiated through static methods.
+ private NodeBadge(Status status, boolean isGlyph, String text, String message) {
+ this.status = status == null ? Status.INFO : status;
+ this.isGlyph = isGlyph;
+ this.text = text;
+ this.message = message;
+ }
+
+ @Override
+ public String toString() {
+ return "{Badge " + status +
+ " (" + text + ")" +
+ (isGlyph ? "*G " : " ") +
+ "\"" + message + "\"}";
+ }
+
+ /**
+ * Returns the badge status.
+ *
+ * @return badge status
+ */
+ public Status status() {
+ return status;
+ }
+
+ /**
+ * Returns true if the text for this badge designates a glyph ID.
+ *
+ * @return true if badge uses glyph
+ */
+ public boolean isGlyph() {
+ return isGlyph;
+ }
+
+ /**
+ * Returns the text for the badge.
+ * Note that if {@link #isGlyph} is true, the text is a glyph ID, otherwise
+ * the text is displayed verbatim in the badge.
+ *
+ * @return text for badge
+ */
+ public String text() {
+ return text;
+ }
+
+ /**
+ * Returns the message associated with the badge.
+ *
+ * @return associated message
+ */
+ public String message() {
+ return message;
+ }
+
+ private static String nonNull(String s) {
+ return s == null ? EMPTY : s;
+ }
+
+ /**
+ * Returns an arbitrary text badge, with default status.
+ *
+ * @param txt the text
+ * @return node badge to display text
+ */
+ public static NodeBadge text(String txt) {
+ // TODO: consider length constraint on txt (3 chars?)
+ return new NodeBadge(Status.INFO, false, nonNull(txt), null);
+ }
+
+ /**
+ * Returns a glyph badge, with default status.
+ *
+ * @param gid the glyph ID
+ * @return node badge to display glyph
+ */
+ public static NodeBadge glyph(String gid) {
+ return new NodeBadge(Status.INFO, true, nonNull(gid), null);
+ }
+
+ /**
+ * Returns a numeric badge, with default status.
+ *
+ * @param n the number
+ * @return node badge to display a number
+ */
+ public static NodeBadge number(int n) {
+ // TODO: consider constraints, e.g. 1 <= n <= 999
+ return new NodeBadge(Status.INFO, false, Integer.toString(n), null);
+ }
+
+ /**
+ * Returns an arbitrary text badge, with the given status.
+ *
+ * @param s the status
+ * @param txt the text
+ * @return node badge to display text
+ */
+ public static NodeBadge text(Status s, String txt) {
+ // TODO: consider length constraint on txt (3 chars?)
+ return new NodeBadge(s, false, nonNull(txt), null);
+ }
+
+ /**
+ * Returns a glyph badge, with the given status.
+ *
+ * @param s the status
+ * @param gid the glyph ID
+ * @return node badge to display glyph
+ */
+ public static NodeBadge glyph(Status s, String gid) {
+ return new NodeBadge(s, true, nonNull(gid), null);
+ }
+
+
+ /**
+ * Returns a numeric badge, with the given status and optional message.
+ *
+ * @param s the status
+ * @param n the number
+ * @return node badge to display a number
+ */
+ public static NodeBadge number(Status s, int n) {
+ // TODO: consider constraints, e.g. 1 <= n <= 999
+ return new NodeBadge(s, false, Integer.toString(n), null);
+ }
+
+ /**
+ * Returns an arbitrary text badge, with the given status and optional
+ * message.
+ *
+ * @param s the status
+ * @param txt the text
+ * @param msg the optional message
+ * @return node badge to display text
+ */
+ public static NodeBadge text(Status s, String txt, String msg) {
+ // TODO: consider length constraint on txt (3 chars?)
+ return new NodeBadge(s, false, nonNull(txt), msg);
+ }
+
+ /**
+ * Returns a glyph badge, with the given status and optional message.
+ *
+ * @param s the status
+ * @param gid the glyph ID
+ * @param msg the optional message
+ * @return node badge to display glyph
+ */
+ public static NodeBadge glyph(Status s, String gid, String msg) {
+ return new NodeBadge(s, true, nonNull(gid), msg);
+ }
+
+
+ /**
+ * Returns a numeric badge, with the given status and optional message.
+ *
+ * @param s the status
+ * @param n the number
+ * @param msg the optional message
+ * @return node badge to display a number
+ */
+ public static NodeBadge number(Status s, int n, String msg) {
+ // TODO: consider constraints, e.g. 1 <= n <= 999
+ return new NodeBadge(s, false, Integer.toString(n), msg);
+ }
+
+}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/NodeHighlight.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/NodeHighlight.java
index 61e10c56..69235089 100644
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/NodeHighlight.java
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/NodeHighlight.java
@@ -20,7 +20,34 @@ package org.onosproject.ui.topo;
* Parent class of {@link DeviceHighlight} and {@link HostHighlight}.
*/
public abstract class NodeHighlight extends AbstractHighlight {
+
+ private NodeBadge badge;
+
+ /**
+ * Constructs a node highlight entity.
+ *
+ * @param type element type
+ * @param elementId element identifier
+ */
public NodeHighlight(TopoElementType type, String elementId) {
super(type, elementId);
}
+
+ /**
+ * Sets the badge for this node.
+ *
+ * @param badge badge to apply
+ */
+ public void setBadge(NodeBadge badge) {
+ this.badge = badge;
+ }
+
+ /**
+ * Returns the badge for this node, if any.
+ *
+ * @return badge, or null
+ */
+ public NodeBadge badge() {
+ return badge;
+ }
}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/TopoConstants.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/TopoConstants.java
index 0f42b628..e2034fa7 100644
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/TopoConstants.java
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/TopoConstants.java
@@ -32,14 +32,17 @@ public final class TopoConstants {
public static final class Glyphs {
public static final String UNKNOWN = "unknown";
public static final String BIRD = "bird";
+ public static final String QUERY = "query";
public static final String NODE = "node";
public static final String SWITCH = "switch";
public static final String ROADM = "roadm";
public static final String ENDSTATION = "endstation";
public static final String ROUTER = "router";
public static final String BGP_SPEAKER = "bgpSpeaker";
+ public static final String MICROWAVE = "microwave";
public static final String CHAIN = "chain";
public static final String CROWN = "crown";
+ public static final String LOCK = "lock";
public static final String TOPO = "topo";
public static final String REFRESH = "refresh";
public static final String GARBAGE = "garbage";
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/TopoJson.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/TopoJson.java
index 8df03169..4030abdc 100644
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/TopoJson.java
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/TopoJson.java
@@ -37,6 +37,11 @@ public final class TopoJson {
static final String ID = "id";
static final String LABEL = "label";
static final String CSS = "css";
+ static final String BADGE = "badge";
+ static final String STATUS = "status";
+ static final String TXT = "txt";
+ static final String GID = "gid";
+ static final String MSG = "msg";
static final String TITLE = "title";
static final String TYPE = "type";
@@ -97,12 +102,26 @@ public final class TopoJson {
return payload;
}
+ private static ObjectNode json(NodeBadge b) {
+ ObjectNode n = objectNode()
+ .put(STATUS, b.status().code())
+ .put(b.isGlyph() ? GID : TXT, b.text());
+ if (b.message() != null) {
+ n.put(MSG, b.message());
+ }
+ return n;
+ }
+
private static ObjectNode json(DeviceHighlight dh) {
ObjectNode n = objectNode()
.put(ID, dh.elementId());
if (dh.subdued()) {
n.put(SUBDUE, true);
}
+ NodeBadge badge = dh.badge();
+ if (badge != null) {
+ n.set(BADGE, json(badge));
+ }
return n;
}
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/NodeBadgeTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/NodeBadgeTest.java
new file mode 100644
index 00000000..c8243695
--- /dev/null
+++ b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/NodeBadgeTest.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.ui.topo;
+
+import org.junit.Test;
+import org.onosproject.ui.topo.NodeBadge.Status;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Unit tests for {@link NodeBadge}.
+ */
+public class NodeBadgeTest {
+
+ private static final String MSG = "a msg";
+ private static final String TXT = "text";
+ private static final String GID = "glyph-id";
+ private static final int NUM = 42;
+ private static final String NUM_STR = Integer.toString(NUM);
+
+ private static final String WR_S = "wrong status";
+ private static final String WR_B = "wrong boolean";
+ private static final String WR_T = "wrong text";
+ private static final String WR_M = "wrong message";
+ private static final String WR_SF = "wrong string format";
+
+ private NodeBadge badge;
+
+ private void checkFields(NodeBadge b, Status s, boolean g,
+ String txt, String msg) {
+ assertEquals(WR_S, s, b.status());
+ assertEquals(WR_B, g, b.isGlyph());
+ assertEquals(WR_T, txt, b.text());
+ assertEquals(WR_M, msg, b.message());
+ }
+
+ @Test
+ public void badgeTypes() {
+ assertEquals(WR_SF, "i", Status.INFO.code());
+ assertEquals(WR_SF, "w", Status.WARN.code());
+ assertEquals(WR_SF, "e", Status.ERROR.code());
+ assertEquals("unexpected size", 3, Status.values().length);
+ }
+
+ @Test
+ public void textOnly() {
+ badge = NodeBadge.text(TXT);
+ checkFields(badge, Status.INFO, false, TXT, null);
+ }
+
+ @Test
+ public void glyphOnly() {
+ badge = NodeBadge.glyph(GID);
+ checkFields(badge, Status.INFO, true, GID, null);
+ }
+
+ @Test
+ public void numberOnly() {
+ badge = NodeBadge.number(NUM);
+ checkFields(badge, Status.INFO, false, NUM_STR, null);
+ }
+
+ @Test
+ public void textInfo() {
+ badge = NodeBadge.text(Status.INFO, TXT);
+ checkFields(badge, Status.INFO, false, TXT, null);
+ }
+
+ @Test
+ public void glyphWarn() {
+ badge = NodeBadge.glyph(Status.WARN, GID);
+ checkFields(badge, Status.WARN, true, GID, null);
+ }
+
+ @Test
+ public void numberError() {
+ badge = NodeBadge.number(Status.ERROR, NUM);
+ checkFields(badge, Status.ERROR, false, NUM_STR, null);
+ }
+
+ @Test
+ public void textInfoMsg() {
+ badge = NodeBadge.text(Status.INFO, TXT, MSG);
+ checkFields(badge, Status.INFO, false, TXT, MSG);
+ }
+
+ @Test
+ public void glyphWarnMsg() {
+ badge = NodeBadge.glyph(Status.WARN, GID, MSG);
+ checkFields(badge, Status.WARN, true, GID, MSG);
+ }
+
+ @Test
+ public void numberErrorMsg() {
+ badge = NodeBadge.number(Status.ERROR, NUM, MSG);
+ checkFields(badge, Status.ERROR, false, NUM_STR, MSG);
+ }
+}
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/TopoJsonTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/TopoJsonTest.java
index ac0051cd..50aabf8e 100644
--- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/TopoJsonTest.java
+++ b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/TopoJsonTest.java
@@ -21,14 +21,22 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.Test;
import org.onosproject.ui.JsonUtils;
import org.onosproject.ui.topo.Highlights.Amount;
+import org.onosproject.ui.topo.NodeBadge.Status;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
/**
* Unit tests for {@link TopoJson}.
*/
public class TopoJsonTest {
+ private static final String DEV1 = "device-1";
+ private static final String DEV2 = "device-2";
+ private static final String SOME_MSG = "Hello there";
+ private static final String GID = "glyph-ID";
+
private ObjectNode payload;
private void checkArrayLength(String key, int expLen) {
@@ -68,4 +76,42 @@ public class TopoJsonTest {
String subdue = JsonUtils.string(payload, TopoJson.SUBDUE);
assertEquals("not max", "max", subdue);
}
+
+ @Test
+ public void badgedDevice() {
+ Highlights h = new Highlights();
+ DeviceHighlight dh = new DeviceHighlight(DEV1);
+ dh.setBadge(NodeBadge.number(7));
+ h.add(dh);
+
+ dh = new DeviceHighlight(DEV2);
+ dh.setBadge(NodeBadge.glyph(Status.WARN, GID, SOME_MSG));
+ h.add(dh);
+
+ payload = TopoJson.json(h);
+// System.out.println(payload);
+
+ // dig into the payload, and verify the badges are set on the devices
+ ArrayNode a = (ArrayNode) payload.get(TopoJson.DEVICES);
+
+ ObjectNode d = (ObjectNode) a.get(0);
+ assertEquals("wrong device id", DEV1, d.get(TopoJson.ID).asText());
+
+ ObjectNode b = (ObjectNode) d.get(TopoJson.BADGE);
+ assertNotNull("missing badge", b);
+ assertEquals("wrong status code", "i", b.get(TopoJson.STATUS).asText());
+ assertEquals("wrong text", "7", b.get(TopoJson.TXT).asText());
+ assertNull("glyph?", b.get(TopoJson.GID));
+ assertNull("msg?", b.get(TopoJson.MSG));
+
+ d = (ObjectNode) a.get(1);
+ assertEquals("wrong device id", DEV2, d.get(TopoJson.ID).asText());
+
+ b = (ObjectNode) d.get(TopoJson.BADGE);
+ assertNotNull("missing badge", b);
+ assertEquals("wrong status code", "w", b.get(TopoJson.STATUS).asText());
+ assertNull("text?", b.get(TopoJson.TXT));
+ assertEquals("wrong text", GID, b.get(TopoJson.GID).asText());
+ assertEquals("wrong message", SOME_MSG, b.get(TopoJson.MSG).asText());
+ }
}