use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class PortCodecTest method portCodecTest.
@Test
public void portCodecTest() {
final MockCodecContext context = new MockCodecContext();
context.registerService(DeviceService.class, new DeviceServiceAdapter());
final JsonCodec<Port> codec = context.codec(Port.class);
assertThat(codec, is(notNullValue()));
final Port pojoIn = port;
assertJsonEncodable(context, codec, pojoIn);
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class DevicesWebResource method getDevicePorts.
/**
* Gets ports of infrastructure device.
* Returns details of the specified infrastructure device.
*
* @onos.rsModel DeviceGetPorts
* @param id device identifier
* @return 200 OK with a collection of ports of the given device
*/
@GET
@Path("{id}/ports")
@Produces(MediaType.APPLICATION_JSON)
public Response getDevicePorts(@PathParam("id") String id) {
DeviceService service = get(DeviceService.class);
Device device = nullIsNotFound(service.getDevice(deviceId(id)), DEVICE_NOT_FOUND);
List<Port> ports = checkNotNull(service.getPorts(deviceId(id)), "Ports could not be retrieved");
ObjectNode result = codec(Device.class).encode(device, this);
result.set("ports", codec(Port.class).encode(ports, this));
return ok(result).build();
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class FabricInterpreter method mapOutboundPacket.
@Override
public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet) throws PiInterpreterException {
DeviceId deviceId = packet.sendThrough();
TrafficTreatment treatment = packet.treatment();
// fabric.p4 supports only OUTPUT instructions.
List<Instructions.OutputInstruction> outInstructions = treatment.allInstructions().stream().filter(i -> i.type().equals(OUTPUT)).map(i -> (Instructions.OutputInstruction) i).collect(toList());
if (treatment.allInstructions().size() != outInstructions.size()) {
// There are other instructions that are not of type OUTPUT.
throw new PiInterpreterException("Treatment not supported: " + treatment);
}
ImmutableList.Builder<PiPacketOperation> builder = ImmutableList.builder();
for (Instructions.OutputInstruction outInst : outInstructions) {
if (outInst.port().equals(TABLE)) {
// Logical port. Forward using the switch tables like a regular packet.
builder.add(createPiPacketOperation(packet.data(), -1, true));
} else if (outInst.port().equals(FLOOD)) {
// Logical port. Create a packet operation for each switch port.
final DeviceService deviceService = handler().get(DeviceService.class);
for (Port port : deviceService.getPorts(packet.sendThrough())) {
builder.add(createPiPacketOperation(packet.data(), port.number().toLong(), false));
}
} else if (outInst.port().isLogical()) {
throw new PiInterpreterException(format("Output on logical port '%s' not supported", outInst.port()));
} else {
// Send as-is to given port bypassing all switch tables.
builder.add(createPiPacketOperation(packet.data(), outInst.port().toLong(), false));
}
}
return builder.build();
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class FabricInterpreter method mapInboundPacket.
@Override
public InboundPacket mapInboundPacket(PiPacketOperation packetIn, DeviceId deviceId) throws PiInterpreterException {
// Assuming that the packet is ethernet, which is fine since fabric.p4
// can deparse only ethernet packets.
Ethernet ethPkt;
try {
ethPkt = Ethernet.deserializer().deserialize(packetIn.data().asArray(), 0, packetIn.data().size());
} catch (DeserializationException dex) {
throw new PiInterpreterException(dex.getMessage());
}
// Returns the ingress port packet metadata.
Optional<PiPacketMetadata> packetMetadata = packetIn.metadatas().stream().filter(m -> m.id().equals(FabricConstants.INGRESS_PORT)).findFirst();
if (packetMetadata.isPresent()) {
ImmutableByteSequence portByteSequence = packetMetadata.get().value();
short s = portByteSequence.asReadOnlyBuffer().getShort();
ConnectPoint receivedFrom = new ConnectPoint(deviceId, PortNumber.portNumber(s));
if (!receivedFrom.port().hasName()) {
receivedFrom = translateSwitchPort(receivedFrom);
}
ByteBuffer rawData = ByteBuffer.wrap(packetIn.data().asArray());
return new DefaultInboundPacket(receivedFrom, ethPkt, rawData);
} else {
throw new PiInterpreterException(format("Missing metadata '%s' in packet-in received from '%s': %s", FabricConstants.INGRESS_PORT, deviceId, packetIn));
}
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class PolatisInternalConnectivity method testConnectivity.
/**
* Returns boolean in response to test of whether 2 ports on a given device can be internally connected.
* <p>
* This is a callback method required by the InternalConnectivity behaviour.
* @param inputPortNum Input port number on device
* @param outputPortNum Output port number on device
* @return Indication whether internal connection can be made
*/
@Override
public boolean testConnectivity(PortNumber inputPortNum, PortNumber outputPortNum) {
// is possible through a Polatis switch
if (inputPortNum.equals(outputPortNum)) {
log.debug("Input and output ports cannot be one and the same");
return false;
}
DeviceId deviceID = handler().data().deviceId();
DeviceService deviceService = checkNotNull(this.handler().get(DeviceService.class));
Port inputPort = deviceService.getPort(new ConnectPoint(deviceID, inputPortNum));
Port outputPort = deviceService.getPort(new ConnectPoint(deviceID, outputPortNum));
if (!inputPort.isEnabled()) {
log.debug("Input port is DISABLED");
return false;
}
if (!outputPort.isEnabled()) {
log.debug("Output port is DISABLED");
return false;
}
if (!inputPort.annotations().value(KEY_PORTDIR).equals(VALUE_CC)) {
if (inputPort.annotations().value(KEY_PORTDIR).equals(outputPort.annotations().value(KEY_PORTDIR))) {
log.debug("Dual sided switch and provided input & output ports on same side");
return false;
}
}
// Check if either port is used in an active cross-connect
Set<PortNumber> usedPorts = getUsedPorts();
if (usedPorts.contains(inputPortNum)) {
log.debug("Input port {} is used in an active cross-connect", inputPortNum);
return false;
}
if (usedPorts.contains(outputPortNum)) {
log.debug("Output port {} is used in an active cross-connect", outputPortNum);
return false;
}
return true;
}
Aggregations