Thomas Vachuska

Added Port.Type and plumbed it throughout.

......@@ -40,7 +40,7 @@ import static org.onlab.onos.net.DeviceId.deviceId;
description = "Lists all ports or all ports of a device")
public class DevicePortsListCommand extends DevicesListCommand {
private static final String FMT = " port=%s, state=%s%s";
private static final String FMT = " port=%s, state=%s, type=%s, speed=%s%s";
@Option(name = "-e", aliases = "--enabled", description = "Show only enabled ports",
required = false, multiValued = false)
......@@ -110,10 +110,14 @@ public class DevicePortsListCommand extends DevicesListCommand {
ports.add(mapper.createObjectNode()
.put("port", port.number().toString())
.put("isEnabled", port.isEnabled())
.put("type", port.type().toString().toLowerCase())
.put("portSpeed", port.portSpeed())
.set("annotations", annotations(mapper, port.annotations())));
}
}
return result.put("device", device.id().toString()).set("ports", ports);
result.set("device", json(service, mapper, device));
result.set("ports", ports);
return result;
}
// Determines if a port should be included in output.
......@@ -130,6 +134,7 @@ public class DevicePortsListCommand extends DevicesListCommand {
for (Port port : ports) {
if (isIncluded(port)) {
print(FMT, port.number(), port.isEnabled() ? "enabled" : "disabled",
port.type().toString().toLowerCase(), port.portSpeed(),
annotations(port.annotations()));
}
}
......
......@@ -24,9 +24,27 @@ import static com.google.common.base.MoreObjects.toStringHelper;
*/
public class DefaultPort extends AbstractAnnotated implements Port {
/** Default port speed in Mbps. */
public static final long DEFAULT_SPEED = 1_000;
private final Element element;
private final PortNumber number;
private final boolean isEnabled;
private final Type type;
private final long portSpeed;
/**
* Creates a network element attributed to the specified provider.
*
* @param element parent network element
* @param number port number
* @param isEnabled indicator whether the port is up and active
* @param annotations optional key/value annotations
*/
public DefaultPort(Element element, PortNumber number, boolean isEnabled,
Annotations... annotations) {
this(element, number, isEnabled, Type.COPPER, DEFAULT_SPEED, annotations);
}
/**
* Creates a network element attributed to the specified provider.
......@@ -34,19 +52,49 @@ public class DefaultPort extends AbstractAnnotated implements Port {
* @param element parent network element
* @param number port number
* @param isEnabled indicator whether the port is up and active
* @param type port type
* @param portSpeed port speed in Mbs
* @param annotations optional key/value annotations
*/
public DefaultPort(Element element, PortNumber number,
boolean isEnabled, Annotations... annotations) {
public DefaultPort(Element element, PortNumber number, boolean isEnabled,
Type type, long portSpeed, Annotations... annotations) {
super(annotations);
this.element = element;
this.number = number;
this.isEnabled = isEnabled;
this.type = type;
this.portSpeed = portSpeed;
}
@Override
public Element element() {
return element;
}
@Override
public PortNumber number() {
return number;
}
@Override
public boolean isEnabled() {
return isEnabled;
}
@Override
public Type type() {
return type;
}
@Override
public long portSpeed() {
return portSpeed;
}
@Override
public int hashCode() {
return Objects.hash(number, isEnabled);
return Objects.hash(number, isEnabled, type, portSpeed);
}
@Override
......@@ -58,7 +106,9 @@ public class DefaultPort extends AbstractAnnotated implements Port {
final DefaultPort other = (DefaultPort) obj;
return Objects.equals(this.element.id(), other.element.id()) &&
Objects.equals(this.number, other.number) &&
Objects.equals(this.isEnabled, other.isEnabled);
Objects.equals(this.isEnabled, other.isEnabled) &&
Objects.equals(this.type, other.type) &&
Objects.equals(this.portSpeed, other.portSpeed);
}
return false;
}
......@@ -69,22 +119,9 @@ public class DefaultPort extends AbstractAnnotated implements Port {
.add("element", element.id())
.add("number", number)
.add("isEnabled", isEnabled)
.add("type", type)
.add("portSpeed", portSpeed)
.toString();
}
@Override
public PortNumber number() {
return number;
}
@Override
public boolean isEnabled() {
return isEnabled;
}
@Override
public Element element() {
return element;
}
}
......
......@@ -21,6 +21,26 @@ package org.onlab.onos.net;
*/
public interface Port extends Annotated {
/** Represents coarse port type classification. */
public enum Type {
/**
* Signifies copper-based connectivity.
*/
COPPER,
/**
* Signifies optical fiber-based connectivity.
*/
FIBER
}
/**
* Returns the parent network element to which this port belongs.
*
* @return parent network element
*/
Element element();
/**
* Returns the port number.
*
......@@ -36,12 +56,18 @@ public interface Port extends Annotated {
boolean isEnabled();
/**
* Returns the parent network element to which this port belongs.
* Returns the port type.
*
* @return parent network element
* @return port type
*/
Element element();
Type type();
// set of port attributes
/**
* Returns the current port speed in Mbps.
*
* @return current port speed
*/
long portSpeed();
// TODO: more attributes?
}
......
......@@ -15,11 +15,12 @@
*/
package org.onlab.onos.net.device;
import com.google.common.base.MoreObjects;
import org.onlab.onos.net.AbstractDescription;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.SparseAnnotations;
import com.google.common.base.MoreObjects;
import static org.onlab.onos.net.Port.Type;
/**
* Default implementation of immutable port description.
......@@ -27,32 +28,62 @@ import com.google.common.base.MoreObjects;
public class DefaultPortDescription extends AbstractDescription
implements PortDescription {
private static final long DEFAULT_SPEED = 1_000;
private final PortNumber number;
private final boolean isEnabled;
private final Type type;
private final long portSpeed;
/**
* Creates a port description using the supplied information.
*
* @param number port number
* @param isEnabled port enabled state
* @param annotations optional key/value annotations map
* @param number port number
* @param isEnabled port enabled state
* @param annotations optional key/value annotations map
*/
public DefaultPortDescription(PortNumber number, boolean isEnabled,
SparseAnnotations... annotations) {
SparseAnnotations... annotations) {
this(number, isEnabled, Type.COPPER, DEFAULT_SPEED, annotations);
}
/**
* Creates a port description using the supplied information.
*
* @param number port number
* @param isEnabled port enabled state
* @param type port type
* @param portSpeed port speed in Mbps
* @param annotations optional key/value annotations map
*/
public DefaultPortDescription(PortNumber number, boolean isEnabled,
Type type, long portSpeed,
SparseAnnotations...annotations) {
super(annotations);
this.number = number;
this.isEnabled = isEnabled;
this.type = type;
this.portSpeed = portSpeed;
}
// Default constructor for serialization
private DefaultPortDescription() {
this.number = null;
this.isEnabled = false;
this.portSpeed = DEFAULT_SPEED;
this.type = Type.COPPER;
}
/**
* Creates a port description using the supplied information.
*
* @param base PortDescription to get basic information from
* @param annotations optional key/value annotations map
* @param base PortDescription to get basic information from
* @param annotations optional key/value annotations map
*/
public DefaultPortDescription(PortDescription base,
SparseAnnotations annotations) {
this(base.portNumber(), base.isEnabled(), annotations);
SparseAnnotations annotations) {
this(base.portNumber(), base.isEnabled(), base.type(), base.portSpeed(),
annotations);
}
@Override
......@@ -66,17 +97,24 @@ public class DefaultPortDescription extends AbstractDescription
}
@Override
public Type type() {
return type;
}
@Override
public long portSpeed() {
return portSpeed;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("number", number)
.add("isEnabled", isEnabled)
.add("type", type)
.add("portSpeed", portSpeed)
.add("annotations", annotations())
.toString();
}
// default constructor for serialization
private DefaultPortDescription() {
this.number = null;
this.isEnabled = false;
}
}
......
......@@ -18,13 +18,13 @@ package org.onlab.onos.net.device;
import org.onlab.onos.net.Description;
import org.onlab.onos.net.PortNumber;
import static org.onlab.onos.net.Port.Type;
/**
* Information about a port.
*/
public interface PortDescription extends Description {
// TODO: possibly relocate this to a common ground so that this can also used by host tracking if required
/**
* Returns the port number.
*
......@@ -39,4 +39,18 @@ public interface PortDescription extends Description {
*/
boolean isEnabled();
/**
* Returns the port type.
*
* @return port type
*/
Type type();
/**
* Returns the current port speed in Mbps.
*
* @return current port speed
*/
long portSpeed();
}
......
......@@ -23,6 +23,8 @@ import org.onlab.packet.ChassisId;
import static org.junit.Assert.assertEquals;
import static org.onlab.onos.net.Device.Type.SWITCH;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.Port.Type.COPPER;
import static org.onlab.onos.net.Port.Type.FIBER;
import static org.onlab.onos.net.PortNumber.portNumber;
/**
......@@ -35,15 +37,16 @@ public class DefaultPortTest {
private static final DeviceId DID2 = deviceId("of:bar");
private static final PortNumber P1 = portNumber(1);
private static final PortNumber P2 = portNumber(2);
private static final long SP1 = 1_000_000;
@Test
public void testEquality() {
Device device = new DefaultDevice(PID, DID1, SWITCH, "m", "h", "s", "n",
new ChassisId());
Port p1 = new DefaultPort(device, portNumber(1), true);
Port p2 = new DefaultPort(device, portNumber(1), true);
Port p3 = new DefaultPort(device, portNumber(2), true);
Port p4 = new DefaultPort(device, portNumber(2), true);
Port p1 = new DefaultPort(device, portNumber(1), true, COPPER, SP1);
Port p2 = new DefaultPort(device, portNumber(1), true, COPPER, SP1);
Port p3 = new DefaultPort(device, portNumber(2), true, FIBER, SP1);
Port p4 = new DefaultPort(device, portNumber(2), true, FIBER, SP1);
Port p5 = new DefaultPort(device, portNumber(1), false);
new EqualsTester().addEqualityGroup(p1, p2)
......@@ -56,10 +59,12 @@ public class DefaultPortTest {
public void basics() {
Device device = new DefaultDevice(PID, DID1, SWITCH, "m", "h", "s", "n",
new ChassisId());
Port port = new DefaultPort(device, portNumber(1), true);
Port port = new DefaultPort(device, portNumber(1), true, FIBER, SP1);
assertEquals("incorrect element", device, port.element());
assertEquals("incorrect number", portNumber(1), port.number());
assertEquals("incorrect state", true, port.isEnabled());
assertEquals("incorrect speed", SP1, port.portSpeed());
assertEquals("incorrect type", FIBER, port.type());
}
}
......
......@@ -67,8 +67,8 @@ import com.google.common.collect.HashMultimap;
@Component(immediate = true)
@Service
public class DeviceManager
extends AbstractProviderRegistry<DeviceProvider, DeviceProviderService>
implements DeviceService, DeviceAdminService, DeviceProviderRegistry {
extends AbstractProviderRegistry<DeviceProvider, DeviceProviderService>
implements DeviceService, DeviceAdminService, DeviceProviderRegistry {
private static final String DEVICE_ID_NULL = "Device ID cannot be null";
private static final String PORT_NUMBER_NULL = "Port number cannot be null";
......@@ -227,8 +227,8 @@ public class DeviceManager
// Personalized device provider service issued to the supplied provider.
private class InternalDeviceProviderService
extends AbstractProviderService<DeviceProvider>
implements DeviceProviderService {
extends AbstractProviderService<DeviceProvider>
implements DeviceProviderService {
InternalDeviceProviderService(DeviceProvider provider) {
super(provider);
......@@ -236,7 +236,7 @@ public class DeviceManager
@Override
public void deviceConnected(DeviceId deviceId,
DeviceDescription deviceDescription) {
DeviceDescription deviceDescription) {
checkNotNull(deviceId, DEVICE_ID_NULL);
checkNotNull(deviceDescription, DEVICE_DESCRIPTION_NULL);
checkValidity();
......@@ -267,7 +267,7 @@ public class DeviceManager
deviceClockProviderService.setMastershipTerm(deviceId, term);
DeviceEvent event = store.createOrUpdateDevice(provider().id(),
deviceId, deviceDescription);
deviceId, deviceDescription);
// If there was a change of any kind, tell the provider
// that this instance is the master.
......@@ -337,14 +337,14 @@ public class DeviceManager
@Override
public void updatePorts(DeviceId deviceId,
List<PortDescription> portDescriptions) {
List<PortDescription> portDescriptions) {
checkNotNull(deviceId, DEVICE_ID_NULL);
checkNotNull(portDescriptions,
"Port descriptions list cannot be null");
"Port descriptions list cannot be null");
checkValidity();
List<DeviceEvent> events = store.updatePorts(this.provider().id(),
deviceId, portDescriptions);
deviceId, portDescriptions);
for (DeviceEvent event : events) {
post(event);
}
......@@ -352,13 +352,13 @@ public class DeviceManager
@Override
public void portStatusChanged(DeviceId deviceId,
PortDescription portDescription) {
PortDescription portDescription) {
checkNotNull(deviceId, DEVICE_ID_NULL);
checkNotNull(portDescription, PORT_DESCRIPTION_NULL);
checkValidity();
final DeviceEvent event = store.updatePortStatus(this.provider().id(),
deviceId, portDescription);
deviceId, portDescription);
if (event != null) {
log.info("Device {} port {} status changed", deviceId, event
.port().number());
......@@ -370,7 +370,7 @@ public class DeviceManager
public void unableToAssertRole(DeviceId deviceId, MastershipRole role) {
// FIXME: implement response to this notification
log.warn("Failed to assert role [{}] onto Device {}", role,
deviceId);
deviceId);
if (role == MastershipRole.MASTER) {
mastershipService.relinquishMastership(deviceId);
// TODO: Shouldn't we be triggering event?
......@@ -393,7 +393,7 @@ public class DeviceManager
// random cache size
private final int cacheSize = 5;
// temporarily stores term number + events to check for duplicates. A hack.
private HashMultimap<Integer, RoleInfo> eventCache =
private HashMultimap<Integer, RoleInfo> eventCache =
HashMultimap.create();
@Override
......@@ -414,7 +414,7 @@ public class DeviceManager
if (!myNodeId.equals(term.master())) {
// something went wrong in consistency, let go
log.warn("Mastership has changed after this event."
+ "Term Service suggests {} for {}", term, did);
+ "Term Service suggests {} for {}", term, did);
// FIXME: Is it possible to let go of MASTER role
// but remain on STANDBY list?
mastershipService.relinquishMastership(did);
......@@ -435,11 +435,12 @@ public class DeviceManager
return;
}
//flag the device as online. Is there a better way to do this?
DeviceEvent devEvent = store.createOrUpdateDevice(device.providerId(), did,
new DefaultDeviceDescription(
did.uri(), device.type(), device.manufacturer(),
device.hwVersion(), device.swVersion(),
device.serialNumber(), device.chassisId()));
DeviceEvent devEvent =
store.createOrUpdateDevice(device.providerId(), did,
new DefaultDeviceDescription(
did.uri(), device.type(), device.manufacturer(),
device.hwVersion(), device.swVersion(),
device.serialNumber(), device.chassisId()));
post(devEvent);
}
applyRole(did, MastershipRole.MASTER);
......@@ -476,7 +477,7 @@ public class DeviceManager
// Store delegate to re-post events emitted from the store.
private class InternalStoreDelegate
implements DeviceStoreDelegate {
implements DeviceStoreDelegate {
@Override
public void notify(DeviceEvent event) {
post(event);
......
......@@ -543,8 +543,9 @@ public class GossipDeviceStore
Port newPort,
Map<PortNumber, Port> ports) {
if (oldPort.isEnabled() != newPort.isEnabled() ||
!AnnotationsUtil.isEqual(oldPort.annotations(), newPort.annotations())) {
oldPort.type() != newPort.type() ||
oldPort.portSpeed() != newPort.portSpeed() ||
!AnnotationsUtil.isEqual(oldPort.annotations(), newPort.annotations())) {
ports.put(oldPort.number(), newPort);
return new DeviceEvent(PORT_UPDATED, device, newPort);
}
......@@ -867,7 +868,10 @@ public class GossipDeviceStore
}
}
return new DefaultPort(device, number, isEnabled, annotations);
return portDesc == null ?
new DefaultPort(device, number, false, annotations) :
new DefaultPort(device, number, isEnabled, portDesc.value().type(),
portDesc.value().portSpeed(), annotations);
}
/**
......
......@@ -115,6 +115,7 @@ public final class KryoNamespaces {
//
ControllerNode.State.class,
Device.Type.class,
Port.Type.class,
ChassisId.class,
DefaultAnnotations.class,
DefaultControllerNode.class,
......
......@@ -15,13 +15,10 @@
*/
package org.onlab.onos.store.serializers;
import static org.junit.Assert.assertEquals;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.PortNumber.portNumber;
import static java.util.Arrays.asList;
import java.nio.ByteBuffer;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
......@@ -50,10 +47,12 @@ import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.util.KryoNamespace;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import java.nio.ByteBuffer;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.PortNumber.portNumber;
public class KryoSerializerTest {
......
......@@ -291,8 +291,9 @@ public class SimpleDeviceStore
Port newPort,
Map<PortNumber, Port> ports) {
if (oldPort.isEnabled() != newPort.isEnabled() ||
oldPort.type() != newPort.type() ||
oldPort.portSpeed() != newPort.portSpeed() ||
!AnnotationsUtil.isEqual(oldPort.annotations(), newPort.annotations())) {
ports.put(oldPort.number(), newPort);
return new DeviceEvent(PORT_UPDATED, device, newPort);
}
......@@ -510,7 +511,10 @@ public class SimpleDeviceStore
}
}
return new DefaultPort(device, number, isEnabled, annotations);
return portDesc == null ?
new DefaultPort(device, number, false, annotations) :
new DefaultPort(device, number, isEnabled, portDesc.type(),
portDesc.portSpeed(), annotations);
}
/**
......
......@@ -23,6 +23,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.net.Device;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.Port;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.device.DefaultDeviceDescription;
import org.onlab.onos.net.device.DefaultPortDescription;
......@@ -43,14 +44,19 @@ import org.onlab.packet.ChassisId;
import org.projectfloodlight.openflow.protocol.OFFactory;
import org.projectfloodlight.openflow.protocol.OFPortConfig;
import org.projectfloodlight.openflow.protocol.OFPortDesc;
import org.projectfloodlight.openflow.protocol.OFPortFeatures;
import org.projectfloodlight.openflow.protocol.OFPortState;
import org.projectfloodlight.openflow.protocol.OFPortStatus;
import org.projectfloodlight.openflow.protocol.OFVersion;
import org.projectfloodlight.openflow.types.PortSpeed;
import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.List;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.Port.Type.COPPER;
import static org.onlab.onos.net.Port.Type.FIBER;
import static org.onlab.onos.openflow.controller.Dpid.dpid;
import static org.onlab.onos.openflow.controller.Dpid.uri;
import static org.slf4j.LoggerFactory.getLogger;
......@@ -63,6 +69,7 @@ import static org.slf4j.LoggerFactory.getLogger;
public class OpenFlowDeviceProvider extends AbstractProvider implements DeviceProvider {
private static final Logger LOG = getLogger(OpenFlowDeviceProvider.class);
private static final long MBPS = 1_000 * 1_000;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceProviderRegistry providerRegistry;
......@@ -122,9 +129,9 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
OpenFlowSwitch sw = controller.getSwitch(dpid(device.id().uri()));
//if (!checkChannel(device, sw)) {
// LOG.error("Failed to probe device {} on sw={}", device, sw);
// LOG.error("Failed to probe device {} on sw={}", device, sw);
// providerService.deviceDisconnected(device.id());
//return;
//return;
//}
// Prompt an update of port information. We can use any XID for this.
......@@ -143,13 +150,13 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
// Checks if the OF channel is connected.
//private boolean checkChannel(Device device, OpenFlowSwitch sw) {
// FIXME if possible, we might want this to be part of
// OpenFlowSwitch interface so the driver interface isn't misused.
// FIXME if possible, we might want this to be part of
// OpenFlowSwitch interface so the driver interface isn't misused.
// if (sw == null || !((OpenFlowSwitchDriver) sw).isConnected()) {
// return false;
// }
// return false;
// }
// return true;
// }
// }
@Override
public void roleChanged(Device device, MastershipRole newRole) {
......@@ -188,7 +195,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
sw.hardwareDescription(),
sw.softwareDescription(),
sw.serialNumber(),
cId);
cId);
providerService.deviceConnected(did, description);
providerService.updatePorts(did, buildPortDescriptions(sw.getPorts()));
}
......@@ -244,8 +251,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
* @param ports the list of ports
* @return list of portdescriptions
*/
private List<PortDescription> buildPortDescriptions(
List<OFPortDesc> ports) {
private List<PortDescription> buildPortDescriptions(List<OFPortDesc> ports) {
final List<PortDescription> portDescs = new ArrayList<>(ports.size());
for (OFPortDesc port : ports) {
portDescs.add(buildPortDescription(port));
......@@ -260,12 +266,25 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
* @return portDescription for the port.
*/
private PortDescription buildPortDescription(OFPortDesc port) {
final PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
final boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) &&
!port.getConfig().contains(OFPortConfig.PORT_DOWN);
return new DefaultPortDescription(portNo, enabled);
PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
boolean enabled =
!port.getState().contains(OFPortState.LINK_DOWN) &&
!port.getConfig().contains(OFPortConfig.PORT_DOWN);
Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER;
return new DefaultPortDescription(portNo, enabled, type, portSpeed(port));
}
private long portSpeed(OFPortDesc port) {
if (port.getVersion() == OFVersion.OF_13) {
return port.getCurrSpeed() / MBPS;
}
PortSpeed portSpeed = PortSpeed.SPEED_NONE;
for (OFPortFeatures feat : port.getCurr()) {
portSpeed = PortSpeed.max(portSpeed, feat.getPortSpeed());
}
return portSpeed.getSpeedBps() / MBPS;
}
}
}
......
......@@ -6,4 +6,4 @@
[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
. $ONOS_ROOT/tools/build/envDefaults
cd $ONOS_ROOT && mvn clean install && cd docs && mvn javadoc:aggregate
cd $ONOS_ROOT && mvn clean install "$@" && cd docs && mvn javadoc:aggregate
......
......@@ -34,6 +34,7 @@ alias mci='mvn clean install'
# Short-hand for ONOS build, package and test.
alias ob='onos-build'
alias obi='onos-build -Dmaven.test.failure.ignore=true'
alias obs='onos-build-selective'
alias op='onos-package'
alias ot='onos-test'
......
......@@ -3,28 +3,33 @@
{
"uri": "of:0000ffffffffff01", "mac": "ffffffffffff01", "type": "ROADM",
"mfr": "Linc", "hw": "OE", "sw": "?", "serial": "?", "name": "ROADM1",
"annotations": { "latitude": 37.6, "longitude": 122.3, "optical.regens": 0 }
"annotations": { "latitude": 37.6, "longitude": 122.3, "optical.regens": 0 },
"ports": [ { "port": 10, "speed": 100000, "type": "FIBER" }, { "port": 20, "speed": 0, "type": "FIBER" } ]
},
{
"uri": "of:0000ffffffffff02", "mac": "ffffffffffff02", "type": "ROADM",
"mfr": "Linc", "hw": "OE", "sw": "?", "serial": "?", "name": "ROADM2",
"annotations": { "latitude": 37.3, "longitude": 121.9, "optical.regens": 0 }
"annotations": { "latitude": 37.3, "longitude": 121.9, "optical.regens": 0 },
"ports": [ { "port": 11, "speed": 100000, "type": "FIBER" }, { "port": 21, "speed": 0, "type": "FIBER" } ]
},
{
"uri": "of:0000ffffffffff03", "mac": "ffffffffffff03", "type": "ROADM",
"mfr": "Linc", "hw": "OE", "sw": "?", "serial": "?", "name": "ROADM3",
"annotations": { "latitude": 33.9, "longitude": 118.4, "optical.regens": 2 }
"annotations": { "latitude": 33.9, "longitude": 118.4, "optical.regens": 2 },
"ports": [ { "port": 30, "speed": 0, "type": "FIBER" }, { "port": 31, "speed": 0, "type": "FIBER" } ]
},
{
"uri": "of:0000ffffffff0001", "mac": "ffffffffff0003", "type": "SWITCH",
"mfr": "Linc", "hw": "PK", "sw": "?", "serial": "?", "name": "ROUTER1",
"annotations": { "latitude": 37.6, "longitude": 122.3 }
"annotations": { "latitude": 37.6, "longitude": 122.3 },
"ports": [ { "port": 1, "speed": 10000, "type": "COPPER" }, { "port": 2, "speed": 100000, "type": "FIBER" } ]
},
{
"uri": "of:0000ffffffff0002", "mac": "ffffffffff0002", "type": "SWITCH",
"mfr": "Linc", "hw": "PK", "sw": "?", "serial": "?", "name": "ROUTER2",
"annotations": { "latitude": 37.3, "longitude": 121.9 }
"annotations": { "latitude": 37.3, "longitude": 121.9 },
"ports": [ { "port": 1, "speed": 10000, "type": "COPPER" }, { "port": 2, "speed": 100000, "type": "FIBER" } ]
}
],
......
......@@ -202,7 +202,7 @@ public final class IpAddress implements Comparable<IpAddress> {
@Override
public int hashCode() {
return Objects.hash(version, octets);
return Objects.hash(version, Arrays.hashCode(octets));
}
@Override
......
......@@ -19,17 +19,21 @@ import com.fasterxml.jackson.databind.JsonNode;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DefaultAnnotations;
import org.onlab.onos.net.Device;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
import org.onlab.onos.net.HostLocation;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.Port;
import org.onlab.onos.net.SparseAnnotations;
import org.onlab.onos.net.device.DefaultDeviceDescription;
import org.onlab.onos.net.device.DefaultPortDescription;
import org.onlab.onos.net.device.DeviceDescription;
import org.onlab.onos.net.device.DeviceProvider;
import org.onlab.onos.net.device.DeviceProviderRegistry;
import org.onlab.onos.net.device.DeviceProviderService;
import org.onlab.onos.net.device.PortDescription;
import org.onlab.onos.net.host.DefaultHostDescription;
import org.onlab.onos.net.host.HostProvider;
import org.onlab.onos.net.host.HostProviderRegistry;
......@@ -45,7 +49,9 @@ import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import java.net.URI;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.onos.net.DeviceId.deviceId;
......@@ -120,7 +126,30 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider {
DeviceDescription desc =
new DefaultDeviceDescription(uri, type, mfr, hw, sw, serial,
cid, annotations);
dps.deviceConnected(deviceId(uri), desc);
DeviceId deviceId = deviceId(uri);
dps.deviceConnected(deviceId, desc);
JsonNode ports = node.get("ports");
if (ports != null) {
parsePorts(dps, deviceId, ports);
}
}
// Parses the given node with list of device ports.
private void parsePorts(DeviceProviderService dps, DeviceId deviceId, JsonNode nodes) {
List<PortDescription> ports = new ArrayList<>();
for (JsonNode node : nodes) {
ports.add(parsePort(node));
}
dps.updatePorts(deviceId, ports);
}
// Parses the given node with port information.
private PortDescription parsePort(JsonNode node) {
Port.Type type = Port.Type.valueOf(node.path("type").asText("COPPER"));
return new DefaultPortDescription(portNumber(node.path("port").asLong(0)),
node.path("enabled").asBoolean(true),
type, node.path("speed").asLong(1_000));
}
// Parses the given JSON and provides links as configured.
......