Search in sources :

Example 21 with OutputInstruction

use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.

the class HostMonitorTest method testMonitorIpv6HostDoesNotExistWithVlan.

@Test
public void testMonitorIpv6HostDoesNotExistWithVlan() throws Exception {
    HostManager hostManager = createMock(HostManager.class);
    DeviceId devId = DeviceId.deviceId("fake");
    short vlan = 5;
    Device device = createMock(Device.class);
    expect(device.id()).andReturn(devId).anyTimes();
    replay(device);
    PortNumber portNum = PortNumber.portNumber(1L);
    Port port = createMock(Port.class);
    expect(port.number()).andReturn(portNum).anyTimes();
    expect(port.isEnabled()).andReturn(true).anyTimes();
    replay(port);
    TestDeviceService deviceService = new TestDeviceService();
    deviceService.addDevice(device, Collections.singleton(port));
    ConnectPoint cp = new ConnectPoint(devId, portNum);
    expect(hostManager.getHostsByIp(TARGET_IPV6_ADDR)).andReturn(Collections.emptySet()).anyTimes();
    replay(hostManager);
    InterfaceService interfaceService = createMock(InterfaceService.class);
    expect(interfaceService.getMatchingInterfaces(TARGET_IPV6_ADDR)).andReturn(Collections.singleton(new Interface(Interface.NO_INTERFACE_NAME, cp, Collections.singletonList(IA2), sourceMac2, VlanId.vlanId(vlan)))).anyTimes();
    replay(interfaceService);
    TestPacketService packetService = new TestPacketService();
    // Run the test
    hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService, deviceService);
    hostMonitor.addMonitoringFor(TARGET_IPV6_ADDR);
    hostMonitor.run();
    // Check that a packet was sent to our PacketService and that it has
    // the properties we expect
    assertEquals(2, packetService.packets.size());
    OutboundPacket packet = packetService.packets.get(0);
    // Check the output port is correct
    assertEquals(1, packet.treatment().immediate().size());
    Instruction instruction = packet.treatment().immediate().get(0);
    assertTrue(instruction instanceof OutputInstruction);
    OutputInstruction oi = (OutputInstruction) instruction;
    assertEquals(portNum, oi.port());
    // Check the output packet is correct (well the important bits anyway)
    final byte[] pktData = new byte[packet.data().remaining()];
    packet.data().get(pktData);
    Ethernet eth = Ethernet.deserializer().deserialize(pktData, 0, pktData.length);
    assertEquals(vlan, eth.getVlanID());
    IPv6 ipv6 = (IPv6) eth.getPayload();
    assertArrayEquals(SOURCE_IPV6_ADDR.toOctets(), ipv6.getSourceAddress());
    NeighborSolicitation ns = (NeighborSolicitation) ipv6.getPayload().getPayload();
    assertArrayEquals(sourceMac2.toBytes(), ns.getOptions().get(0).data());
    assertArrayEquals(TARGET_IPV6_ADDR.toOctets(), ns.getTargetAddress());
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) IPv6(org.onlab.packet.IPv6) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) ConnectPoint(org.onosproject.net.ConnectPoint) OutboundPacket(org.onosproject.net.packet.OutboundPacket) InterfaceService(org.onosproject.net.intf.InterfaceService) Ethernet(org.onlab.packet.Ethernet) NeighborSolicitation(org.onlab.packet.ndp.NeighborSolicitation) PortNumber(org.onosproject.net.PortNumber) Interface(org.onosproject.net.intf.Interface) Test(org.junit.Test)

Example 22 with OutputInstruction

use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.

the class FabricTreatmentInterpreter method mapNextHashedOrSimpleTreatment.

private static PiAction mapNextHashedOrSimpleTreatment(TrafficTreatment treatment, PiTableId tableId, boolean simple) throws PiInterpreterException {
    // Provide mapping for output_hashed and routing_hashed; multicast_hashed
    // can only be invoked with PiAction, hence no mapping. outPort required for
    // all actions. Presence of other instructions will determine which action to map to.
    final PortNumber outPort = ((OutputInstruction) instructionOrFail(treatment, OUTPUT, tableId)).port();
    final ModEtherInstruction ethDst = (ModEtherInstruction) l2Instruction(treatment, ETH_DST);
    final ModEtherInstruction ethSrc = (ModEtherInstruction) l2Instruction(treatment, ETH_SRC);
    final PiAction.Builder actionBuilder = PiAction.builder().withParameter(new PiActionParam(FabricConstants.PORT_NUM, outPort.toLong()));
    if (ethDst != null && ethSrc != null) {
        actionBuilder.withParameter(new PiActionParam(FabricConstants.SMAC, ethSrc.mac().toBytes()));
        actionBuilder.withParameter(new PiActionParam(FabricConstants.DMAC, ethDst.mac().toBytes()));
        // routing_hashed
        return actionBuilder.withId(simple ? FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_SIMPLE : FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).build();
    } else {
        // output_hashed
        return actionBuilder.withId(simple ? FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_SIMPLE : FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_HASHED).build();
    }
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) ModEtherInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction) PortNumber(org.onosproject.net.PortNumber) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 23 with OutputInstruction

use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.

the class FlowModBuilderVer10 method buildActions.

private List<OFAction> buildActions() {
    List<OFAction> acts = new LinkedList<>();
    OFAction act;
    if (treatment == null) {
        return acts;
    }
    for (Instruction i : treatment.immediate()) {
        switch(i.type()) {
            case NOACTION:
                return Collections.emptyList();
            case L2MODIFICATION:
                act = buildL2Modification(i);
                if (act != null) {
                    acts.add(buildL2Modification(i));
                }
                break;
            case L3MODIFICATION:
                act = buildL3Modification(i);
                if (act != null) {
                    acts.add(buildL3Modification(i));
                }
                break;
            case OUTPUT:
                OutputInstruction out = (OutputInstruction) i;
                OFActionOutput.Builder action = factory().actions().buildOutput().setPort(OFPort.of((int) out.port().toLong()));
                if (out.port().equals(PortNumber.CONTROLLER)) {
                    action.setMaxLen(OFPCML_NO_BUFFER);
                }
                acts.add(action.build());
                break;
            case QUEUE:
                SetQueueInstruction queue = (SetQueueInstruction) i;
                if (queue.port() == null) {
                    log.warn("Required argument 'port' undefined for OFActionEnqueue");
                }
                OFActionEnqueue.Builder queueBuilder = factory().actions().buildEnqueue().setQueueId(queue.queueId()).setPort(OFPort.ofInt((int) queue.port().toLong()));
                acts.add(queueBuilder.build());
                break;
            case L0MODIFICATION:
            case L1MODIFICATION:
            case GROUP:
            case TABLE:
            case METADATA:
                log.warn("Instruction type {} not supported with protocol version {}", i.type(), factory().getVersion());
                break;
            default:
                log.warn("Instruction type {} not yet implemented.", i.type());
        }
    }
    return acts;
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) OFActionOutput(org.projectfloodlight.openflow.protocol.action.OFActionOutput) SetQueueInstruction(org.onosproject.net.flow.instructions.Instructions.SetQueueInstruction) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) OFActionEnqueue(org.projectfloodlight.openflow.protocol.action.OFActionEnqueue) ModIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction) ModVlanPcpInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) ModEtherInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction) SetQueueInstruction(org.onosproject.net.flow.instructions.Instructions.SetQueueInstruction) LinkedList(java.util.LinkedList)

Example 24 with OutputInstruction

use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.

the class FlowModBuilderVer13 method buildActions.

private List<OFAction> buildActions(List<Instruction> treatments) {
    if (treatment == null) {
        return Collections.emptyList();
    }
    boolean tableFound = false;
    List<OFAction> actions = new LinkedList<>();
    for (Instruction i : treatments) {
        switch(i.type()) {
            case NOACTION:
                return Collections.emptyList();
            case L0MODIFICATION:
                actions.add(buildL0Modification(i));
                break;
            case L1MODIFICATION:
                actions.add(buildL1Modification(i));
                break;
            case L2MODIFICATION:
                actions.add(buildL2Modification(i));
                break;
            case L3MODIFICATION:
                actions.add(buildL3Modification(i));
                break;
            case L4MODIFICATION:
                actions.add(buildL4Modification(i));
                break;
            case OUTPUT:
                OutputInstruction out = (OutputInstruction) i;
                OFActionOutput.Builder action = factory().actions().buildOutput().setPort(OFPort.of((int) out.port().toLong()));
                if (out.port().equals(PortNumber.CONTROLLER)) {
                    action.setMaxLen(OFPCML_NO_BUFFER);
                }
                actions.add(action.build());
                break;
            case GROUP:
                GroupInstruction group = (GroupInstruction) i;
                OFActionGroup.Builder groupBuilder = factory().actions().buildGroup().setGroup(OFGroup.of(group.groupId().id()));
                actions.add(groupBuilder.build());
                break;
            case QUEUE:
                SetQueueInstruction queue = (SetQueueInstruction) i;
                OFActionSetQueue.Builder queueBuilder = factory().actions().buildSetQueue().setQueueId(queue.queueId());
                actions.add(queueBuilder.build());
                break;
            case TABLE:
                // FIXME: should not occur here.
                tableFound = true;
                break;
            case EXTENSION:
                actions.add(buildExtensionAction(((Instructions.ExtensionInstructionWrapper) i).extensionInstruction()));
                break;
            default:
                log.warn("Instruction type {} not yet implemented.", i.type());
        }
    }
    if (tableFound && actions.isEmpty()) {
        // a goto instruction for the next table
        return Collections.emptyList();
    }
    return actions;
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) OFActionOutput(org.projectfloodlight.openflow.protocol.action.OFActionOutput) OFActionSetQueue(org.projectfloodlight.openflow.protocol.action.OFActionSetQueue) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) ModIPv6FlowLabelInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction) ModOchSignalInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) ModOduSignalIdInstruction(org.onosproject.net.flow.instructions.L1ModificationInstruction.ModOduSignalIdInstruction) ModTransportPortInstruction(org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction) ModEtherInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction) ModTunnelIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction) L4ModificationInstruction(org.onosproject.net.flow.instructions.L4ModificationInstruction) ModMplsLabelInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction) ModIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction) ModArpIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction) ModVlanPcpInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) ModVlanHeaderInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanHeaderInstruction) ModMplsBosInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsBosInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) ModArpEthInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction) ModMplsHeaderInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsHeaderInstruction) GroupInstruction(org.onosproject.net.flow.instructions.Instructions.GroupInstruction) L1ModificationInstruction(org.onosproject.net.flow.instructions.L1ModificationInstruction) ModArpOpInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction) SetQueueInstruction(org.onosproject.net.flow.instructions.Instructions.SetQueueInstruction) OFActionGroup(org.projectfloodlight.openflow.protocol.action.OFActionGroup) LinkedList(java.util.LinkedList) SetQueueInstruction(org.onosproject.net.flow.instructions.Instructions.SetQueueInstruction) GroupInstruction(org.onosproject.net.flow.instructions.Instructions.GroupInstruction)

Example 25 with OutputInstruction

use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.

the class OfdpaPipelineTraceable method handleOutputFlows.

// Handles output flows
private List<FlowEntry> handleOutputFlows(TrafficSelector currentPacket, List<FlowEntry> outputFlows, TrafficSelector.Builder egressPacket, List<PortNumber> outputPorts, PipelineTraceableHitChain currentHitChain, PipelineTraceableOutput.Builder outputBuilder, TrafficSelector initialPacket) {
    // TODO optimization
    // outputFlows contains also last rule of device, so we need filtering for OUTPUT instructions.
    List<FlowEntry> outputFlowEntries = outputFlows.stream().filter(flow -> flow.treatment().allInstructions().stream().filter(instruction -> instruction.type().equals(Instruction.Type.OUTPUT)).count() > 0).collect(Collectors.toList());
    if (outputFlowEntries.size() > 1) {
        outputBuilder.appendToLog("More than one flow rule with OUTPUT instruction");
        log.warn("There cannot be more than one flow entry with OUTPUT instruction for {}", currentPacket);
    }
    if (outputFlowEntries.size() == 1) {
        OutputInstruction outputInstruction = (OutputInstruction) outputFlowEntries.get(0).treatment().allInstructions().stream().filter(instruction -> instruction.type().equals(Instruction.Type.OUTPUT)).findFirst().get();
        buildOutputFromDevice(egressPacket, outputPorts, outputInstruction, currentHitChain, outputBuilder, initialPacket, false);
    }
    return outputFlowEntries;
}
Also used : PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) ConnectPoint(org.onosproject.net.ConnectPoint) DataPlaneEntity(org.onosproject.net.DataPlaneEntity) PipelineTraceable(org.onosproject.net.behaviour.PipelineTraceable) L2_INTERFACE_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_INTERFACE_TYPE) TMAC_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.TMAC_TABLE) Map(java.util.Map) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) IndexTableId(org.onosproject.net.flow.IndexTableId) VLAN_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.VLAN_TABLE) Set(java.util.Set) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) Collectors(java.util.stream.Collectors) L3_MULTICAST_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L3_MULTICAST_TYPE) L2_MULTICAST_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_MULTICAST_TYPE) EthType(org.onlab.packet.EthType) PipelineTraceableOutput(org.onosproject.net.PipelineTraceableOutput) List(java.util.List) PipelineTraceableInput(org.onosproject.net.PipelineTraceableInput) FlowRule(org.onosproject.net.flow.FlowRule) MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) Ofdpa2Pipeline(org.onosproject.driver.pipeline.ofdpa.Ofdpa2Pipeline) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) Pipeliner(org.onosproject.net.behaviour.Pipeliner) PipelineTraceableHitChain(org.onosproject.net.PipelineTraceableHitChain) BRIDGING_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.BRIDGING_TABLE) TableId(org.onosproject.net.flow.TableId) ACL_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.ACL_TABLE) GroupBucket(org.onosproject.net.group.GroupBucket) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) OvsOfdpaPipeline(org.onosproject.driver.pipeline.ofdpa.OvsOfdpaPipeline) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) PipelineTraceablePacket(org.onosproject.net.PipelineTraceablePacket) L2_FLOOD_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_FLOOD_TYPE) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) MPLS_L3_TYPE_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.MPLS_L3_TYPE_TABLE) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) GroupId(org.onosproject.core.GroupId) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MULTICAST_ROUTING_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.MULTICAST_ROUTING_TABLE) Comparator(java.util.Comparator) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) FlowEntry(org.onosproject.net.flow.FlowEntry)

Aggregations

OutputInstruction (org.onosproject.net.flow.instructions.Instructions.OutputInstruction)34 Instruction (org.onosproject.net.flow.instructions.Instruction)21 PortNumber (org.onosproject.net.PortNumber)17 DeviceId (org.onosproject.net.DeviceId)15 ConnectPoint (org.onosproject.net.ConnectPoint)11 Port (org.onosproject.net.Port)10 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)9 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)7 Criterion (org.onosproject.net.flow.criteria.Criterion)7 Group (org.onosproject.net.group.Group)7 Collection (java.util.Collection)6 DeviceService (org.onosproject.net.device.DeviceService)6 FlowEntry (org.onosproject.net.flow.FlowEntry)6 ImmutableList (com.google.common.collect.ImmutableList)5 HashSet (java.util.HashSet)5 Ethernet (org.onlab.packet.Ethernet)5 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)5 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)5 ModEtherInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction)5 ModVlanIdInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction)5