Search in sources :

Example 86 with Port

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);
}
Also used : DefaultPort(org.onosproject.net.DefaultPort) Port(org.onosproject.net.Port) DeviceServiceAdapter(org.onosproject.net.device.DeviceServiceAdapter) Test(org.junit.Test)

Example 87 with Port

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 88 with Port

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();
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) PACKET_OUT(org.onosproject.net.pi.model.PiPacketOperationType.PACKET_OUT) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) ImmutableList(com.google.common.collect.ImmutableList) DeserializationException(org.onlab.packet.DeserializationException) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ImmutableByteSequence.copyFrom(org.onlab.util.ImmutableByteSequence.copyFrom) Port(org.onosproject.net.Port) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FLOOD(org.onosproject.net.PortNumber.FLOOD) Instructions(org.onosproject.net.flow.instructions.Instructions) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Collection(java.util.Collection) Set(java.util.Set) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) FabricConstants(org.onosproject.pipelines.fabric.FabricConstants) String.format(java.lang.String.format) CONTROLLER(org.onosproject.net.PortNumber.CONTROLLER) PiAction(org.onosproject.net.pi.runtime.PiAction) TABLE(org.onosproject.net.PortNumber.TABLE) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) DriverHandler(org.onosproject.net.driver.DriverHandler) InboundPacket(org.onosproject.net.packet.InboundPacket) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) OUTPUT(org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT) DeviceId(org.onosproject.net.DeviceId) ImmutableList(com.google.common.collect.ImmutableList) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) Instructions(org.onosproject.net.flow.instructions.Instructions) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation)

Example 89 with Port

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));
    }
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) PACKET_OUT(org.onosproject.net.pi.model.PiPacketOperationType.PACKET_OUT) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) ImmutableList(com.google.common.collect.ImmutableList) DeserializationException(org.onlab.packet.DeserializationException) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ImmutableByteSequence.copyFrom(org.onlab.util.ImmutableByteSequence.copyFrom) Port(org.onosproject.net.Port) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FLOOD(org.onosproject.net.PortNumber.FLOOD) Instructions(org.onosproject.net.flow.instructions.Instructions) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Collection(java.util.Collection) Set(java.util.Set) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) FabricConstants(org.onosproject.pipelines.fabric.FabricConstants) String.format(java.lang.String.format) CONTROLLER(org.onosproject.net.PortNumber.CONTROLLER) PiAction(org.onosproject.net.pi.runtime.PiAction) TABLE(org.onosproject.net.PortNumber.TABLE) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) DriverHandler(org.onosproject.net.driver.DriverHandler) InboundPacket(org.onosproject.net.packet.InboundPacket) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) OUTPUT(org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) Ethernet(org.onlab.packet.Ethernet) ConnectPoint(org.onosproject.net.ConnectPoint) ByteBuffer(java.nio.ByteBuffer) DeserializationException(org.onlab.packet.DeserializationException) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence)

Example 90 with Port

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;
}
Also used : DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

Port (org.onosproject.net.Port)200 DeviceService (org.onosproject.net.device.DeviceService)92 PortNumber (org.onosproject.net.PortNumber)85 ConnectPoint (org.onosproject.net.ConnectPoint)78 DeviceId (org.onosproject.net.DeviceId)76 Device (org.onosproject.net.Device)63 List (java.util.List)51 Set (java.util.Set)47 Optional (java.util.Optional)43 DefaultPort (org.onosproject.net.DefaultPort)38 Logger (org.slf4j.Logger)38 ArrayList (java.util.ArrayList)36 Collectors (java.util.stream.Collectors)35 Collections (java.util.Collections)34 Collection (java.util.Collection)33 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)33 Test (org.junit.Test)31 Ethernet (org.onlab.packet.Ethernet)31 Map (java.util.Map)29 Sets (com.google.common.collect.Sets)28