alshabib

updateports functional

package org.onlab.onos.net;
import com.google.common.primitives.UnsignedLongs;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.primitives.UnsignedLongs;
/**
* Representation of a port number.
......@@ -17,9 +15,6 @@ public final class PortNumber {
// Public creation is prohibited
private PortNumber(long number) {
checkArgument(number >= 0 && number < MAX_NUMBER,
"Port number %d is outside the supported range [0, %d)",
number, MAX_NUMBER);
this.number = number;
}
......
package org.onlab.onos.net;
import com.google.common.testing.EqualsTester;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.onlab.onos.net.PortNumber.portNumber;
import org.junit.Test;
import com.google.common.testing.EqualsTester;
/**
* Test of the port number.
*/
public class PortNumberTest extends ElementIdTest {
@Override
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(portNumber(123),
portNumber("123"))
.addEqualityGroup(portNumber(123),
portNumber("123"))
.addEqualityGroup(portNumber(321))
.testEquals();
}
......@@ -25,13 +27,5 @@ public class PortNumberTest extends ElementIdTest {
assertEquals("incorrect long value", 12345, portNumber(12345).toLong());
}
@Test(expected = IllegalArgumentException.class)
public void negative() {
portNumber(-1);
}
@Test(expected = IllegalArgumentException.class)
public void tooBig() {
portNumber((2L * Integer.MAX_VALUE) + 2);
}
}
......
package org.onlab.onos.of.drivers.impl;
import java.util.Collections;
import java.util.List;
import org.onlab.onos.of.controller.Dpid;
import org.onlab.onos.of.controller.driver.AbstractOpenFlowSwitch;
import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
import org.projectfloodlight.openflow.protocol.OFMessage;
import org.projectfloodlight.openflow.protocol.OFPortDesc;
/**
* OFDescriptionStatistics Vendor (Manufacturer Desc.): Nicira, Inc. Make
......@@ -56,4 +58,11 @@ public class OFSwitchImplOVS10 extends AbstractOpenFlowSwitch {
public void write(List<OFMessage> msgs) {
channel.write(msgs);
}
@Override
public List<OFPortDesc> getPorts() {
return Collections.unmodifiableList(features.getPorts());
}
}
......
......@@ -30,7 +30,9 @@ import org.onlab.onos.of.controller.OpenFlowController;
import org.onlab.onos.of.controller.OpenFlowSwitch;
import org.onlab.onos.of.controller.OpenFlowSwitchListener;
import org.onlab.onos.of.controller.RoleState;
import org.projectfloodlight.openflow.protocol.OFPortConfig;
import org.projectfloodlight.openflow.protocol.OFPortDesc;
import org.projectfloodlight.openflow.protocol.OFPortState;
import org.slf4j.Logger;
/**
......@@ -50,7 +52,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
private DeviceProviderService providerService;
private OpenFlowSwitchListener listener = new InternalDeviceProvider();
private final OpenFlowSwitchListener listener = new InternalDeviceProvider();
/**
* Creates an OpenFlow device provider.
......@@ -119,17 +121,6 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
providerService.updatePorts(deviceId(uri), buildPortDescriptions(sw.getPorts()));
}
private List<PortDescription> buildPortDescriptions(
List<OFPortDesc> ports) {
List<PortDescription> portDescs = new ArrayList<PortDescription>();
for (OFPortDesc port : ports) {
PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
portDescs.add(new DefaultPortDescription(portNo,
port.getState()));
}
}
@Override
public void switchRemoved(Dpid dpid) {
if (providerService == null) {
......@@ -149,6 +140,21 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
return uri;
}
private List<PortDescription> buildPortDescriptions(
List<OFPortDesc> ports) {
final List<PortDescription> portDescs = new ArrayList<PortDescription>();
PortNumber portNo;
boolean enabled;
for (OFPortDesc port : ports) {
portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
enabled = !port.getState().contains(OFPortState.LINK_DOWN) &&
!port.getConfig().contains(OFPortConfig.PORT_DOWN);
portDescs.add(new DefaultPortDescription(portNo,
enabled));
}
return portDescs;
}
}
}
......