Java Code Examples for org.onosproject.net.PortNumber#isLogical()

The following examples show how to use org.onosproject.net.PortNumber#isLogical() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultMep.java    From onos with Apache License 2.0 6 votes vote down vote up
protected DefaultMepBuilder(MepId mepId, DeviceId deviceId, PortNumber port,
        MepDirection direction, MdId mdId, MaIdShort maId)
        throws CfmConfigException {
    if (port.isLogical()) {
        throw new CfmConfigException("Port must be physical. Rejecting; " + port.toString());
    } else if (mepId == null) {
        throw new CfmConfigException("MepId is null");
    } else if (mdId == null) {
        throw new CfmConfigException("MdId is null");
    } else if (maId == null) {
        throw new CfmConfigException("MaId is null");
    }
    this.mepId = mepId;
    this.deviceId = deviceId;
    this.port = port;
    this.direction = direction;
    this.mdId = mdId;
    this.maId = maId;
}
 
Example 2
Source File: OpenConfigGnmiPortAdminBehaviour.java    From onos with Apache License 2.0 5 votes vote down vote up
private void doEnable(PortNumber portNumber, boolean enabled) {
    if (portNumber.isLogical()) {
        log.warn("Cannot update port status for logical port {} on {}",
                 portNumber, deviceId);
        return;
    }
    final Gnmi.Path path = Gnmi.Path.newBuilder()
            .addElem(Gnmi.PathElem.newBuilder().setName("interfaces").build())
            .addElem(Gnmi.PathElem.newBuilder().setName("interface")
                             .putKey("name", portNumber.name()).build())
            .addElem(Gnmi.PathElem.newBuilder().setName("config").build())
            .addElem(Gnmi.PathElem.newBuilder().setName("enabled").build())
            .build();
    final Gnmi.TypedValue value = Gnmi.TypedValue.newBuilder()
            .setBoolVal(enabled)
            .build();
    final Gnmi.SetRequest request = Gnmi.SetRequest.newBuilder()
            .addUpdate(Gnmi.Update.newBuilder()
                               .setPath(path)
                               .setVal(value)
                               .build())
            .build();

    // Async submit request and forget about it. In case of errors, the
    // client will log them. In case of success, we should receive a gNMI
    // Update over the Subscribe RPC with the new oper status.
    client.set(request);
}
 
Example 3
Source File: BasicInterpreterImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
private PiAction outputPiAction(OutputInstruction outInstruction, PiActionId piActionId)
        throws PiInterpreterException {
    PortNumber port = outInstruction.port();
    if (!port.isLogical()) {
        return PiAction.builder()
                .withId(piActionId)
                .withParameter(new PiActionParam(PORT, port.toLong()))
                .build();
    } else if (port.equals(CONTROLLER)) {
        return PiAction.builder().withId(INGRESS_TABLE0_CONTROL_SEND_TO_CPU).build();
    } else {
        throw new PiInterpreterException(format(
                "Egress on logical port '%s' not supported", port));
    }
}
 
Example 4
Source File: DefaultVirtualFlowRuleProvider.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Extract egress connect point of the physical network
 * from the requested traffic treatment.
 *
 * @param networkId the virtual network identifier
 * @param deviceId the virtual device identifier
 * @param treatment the traffic treatment to extract ingress point
 * @return the egress connect point of the physical network
 */
private ConnectPoint extractEgressPoints(NetworkId networkId,
                                              DeviceId deviceId,
                                              TrafficTreatment treatment) {

    Set<VirtualPort> vPorts = vnService
            .getVirtualPorts(networkId, deviceId);

    PortNumber vOutPortNum = treatment.allInstructions().stream()
            .filter(i -> i.type() == Instruction.Type.OUTPUT)
            .map(i -> ((Instructions.OutputInstruction) i).port())
            .findFirst().get();

    Optional<ConnectPoint> optionalCpOut = vPorts.stream()
            .filter(v -> v.number().equals(vOutPortNum))
            .map(VirtualPort::realizedBy)
            .findFirst();

    if (!optionalCpOut.isPresent()) {
        if (vOutPortNum.isLogical()) {
            return new ConnectPoint(DeviceId.deviceId("vNet"), vOutPortNum);
        }

        log.warn("Port {} is not realized yet, in Network {}, Device {}",
                 vOutPortNum, networkId, deviceId);
        return null;
    }

    return optionalCpOut.get();
}
 
Example 5
Source File: PipelineInterpreterImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet)
        throws PiInterpreterException {

    TrafficTreatment treatment = packet.treatment();

    // We support only packet-out with OUTPUT instructions.
    if (treatment.allInstructions().size() != 1 &&
            treatment.allInstructions().get(0).type() != OUTPUT) {
        throw new PiInterpreterException(
                "Treatment not supported: " + treatment.toString());
    }

    Instruction instruction = treatment.allInstructions().get(0);
    PortNumber port = ((OutputInstruction) instruction).port();
    List<PiPacketOperation> piPacketOps = Lists.newArrayList();

    if (!port.isLogical()) {
        piPacketOps.add(createPiPacketOp(packet.data(), port.toLong()));
    } else if (port.equals(FLOOD)) {
        // Since mytunnel.p4 does not support flooding, we create a packet
        // operation for each switch port.
        DeviceService deviceService = handler().get(DeviceService.class);
        DeviceId deviceId = packet.sendThrough();
        for (Port p : deviceService.getPorts(deviceId)) {
            piPacketOps.add(createPiPacketOp(packet.data(), p.number().toLong()));
        }
    } else {
        throw new PiInterpreterException(format(
                "Output on logical port '%s' not supported", port));
    }

    return piPacketOps;
}
 
Example 6
Source File: DefaultCheckLoop.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Process one output instruction.
 *
 * Params are passed from processOneInstruction directly,
 * and obey the same rules.
 *
 * @param instOne the instruction to be processed
 * @param currentDeviceId id of the device we are now in
 * @param initPkt the packet before being copied
 * @param matchedPkt the packet which matched the flow entry,
 *                   to which this instruction belongs
 * @param isFindLoop indicate if it is invoked by findLoop method
 * @param firstEntry the flow entry from which the packet is generated
 * @return true, if a loop is discovered;
 *         false, 1. invoked by matchDeviceFlows method, and detected no loop;
 *                2. invoked by findLoop method
 */
private boolean processOneOutputInstruction(Instruction instOne,
                                            DeviceId currentDeviceId,
                                            TsLoopPacket initPkt,
                                            TsLoopPacket matchedPkt,
                                            boolean isFindLoop,
                                            FlowEntry firstEntry) {
    OutputInstruction instOutput = (OutputInstruction) instOne;
    PortNumber instPort = instOutput.port();

    if (!instPort.isLogical()) {
        // single OUTPUT - NIC or normal port

        Set<Link> dstLink = tsGetEgressLinks(
                new ConnectPoint(currentDeviceId, instPort));
        if (!dstLink.isEmpty()) {

            // TODO - now, just deal with the first destination.
            // will there be more destinations?

            Link dstThisLink = dstLink.iterator().next();
            ConnectPoint dstPoint = dstThisLink.dst();

            // check output to devices only (output to a host is normal)
            if (isDevice(dstPoint)) {
                PortCriterion oldInPort =
                        updatePktInportPerHop(matchedPkt, dstPoint);
                matchedPkt.pushPathLink(dstThisLink);
                TsLoopPacket newNewPkt = matchedPkt.copyPacketMatch();

                boolean loopFound =
                        matchDeviceFlows(dstPoint.deviceId(), newNewPkt);
                if (isFindLoop) {
                    if (loopFound) {
                        loops.add(newNewPkt);
                        updateExcludeDeviceSet(newNewPkt);
                    }
                    matchedPkt.resetLinkFlow(firstEntry);
                } else {
                    if (loopFound) {
                        initPkt.handInLoopMatch(newNewPkt);
                        return true;
                    }
                    matchedPkt.popPathLink();
                }
                restorePktInportPerHop(matchedPkt, oldInPort);
            }
        } else {
            if (!isFindLoop) {
                //TODO - NEED
                log.warn("no link connecting at device {}, port {}",
                        currentDeviceId, instPort);
            }
        }
    } else if (instPort.equals(PortNumber.IN_PORT)) {
        //TODO - in the future,
        // we may need to resolve this condition 1
        log.warn("can not handle {} port now.", PortNumber.IN_PORT);
    } else if (instPort.equals(PortNumber.NORMAL) ||
            instPort.equals(PortNumber.FLOOD) ||
            instPort.equals(PortNumber.ALL)) {
        //TODO - in the future,
        // we may need to resolve this condition 2
        log.warn("can not handle {}/{}/{} now.",
                PortNumber.NORMAL, PortNumber.FLOOD, PortNumber.ALL);
    }
    return false;
}
 
Example 7
Source File: PipelineInterpreterImpl.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId)
        throws PiInterpreterException {

    if (piTableId != TABLE_L2_FWD_ID) {
        throw new PiInterpreterException(
                "Can map treatments only for 't_l2_fwd' table");
    }

    if (treatment.allInstructions().size() == 0) {
        // 0 instructions means "NoAction"
        return PiAction.builder().withId(ACT_ID_NOP).build();
    } else if (treatment.allInstructions().size() > 1) {
        // We understand treatments with only 1 instruction.
        throw new PiInterpreterException("Treatment has multiple instructions");
    }

    // Get the first and only instruction.
    Instruction instruction = treatment.allInstructions().get(0);

    if (instruction.type() != OUTPUT) {
        // We can map only instructions of type OUTPUT.
        throw new PiInterpreterException(format(
                "Instruction of type '%s' not supported", instruction.type()));
    }

    OutputInstruction outInstruction = (OutputInstruction) instruction;
    PortNumber port = outInstruction.port();
    if (!port.isLogical()) {
        return PiAction.builder()
                .withId(ACT_ID_SET_EGRESS_PORT)
                .withParameter(new PiActionParam(
                        ACT_PARAM_ID_PORT, copyFrom(port.toLong())))
                .build();
    } else if (port.equals(CONTROLLER)) {
        return PiAction.builder()
                .withId(ACT_ID_SEND_TO_CPU)
                .build();
    } else {
        throw new PiInterpreterException(format(
                "Output on logical port '%s' not supported", port));
    }
}