Search in sources :

Example 36 with Instruction

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

the class HostMonitorTest method testMonitorIpv6HostDoesNotExist.

@Test
public void testMonitorIpv6HostDoesNotExist() throws Exception {
    HostManager hostManager = createMock(HostManager.class);
    DeviceId devId = DeviceId.deviceId("fake");
    Device device = createMock(Device.class);
    expect(device.id()).andReturn(devId).anyTimes();
    replay(device);
    PortNumber portNum = PortNumber.portNumber(2L);
    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.NONE))).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(Ethernet.VLAN_UNTAGGED, 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 37 with Instruction

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

the class HostMonitorTest method testMonitorIpv4HostDoesNotExist.

@Test
public void testMonitorIpv4HostDoesNotExist() throws Exception {
    HostManager hostManager = createMock(HostManager.class);
    DeviceId devId = DeviceId.deviceId("fake");
    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_IPV4_ADDR)).andReturn(Collections.emptySet()).anyTimes();
    replay(hostManager);
    InterfaceService interfaceService = createMock(InterfaceService.class);
    expect(interfaceService.getMatchingInterfaces(TARGET_IPV4_ADDR)).andReturn(Collections.singleton(new Interface(Interface.NO_INTERFACE_NAME, cp, Collections.singletonList(IA1), sourceMac, VlanId.NONE))).anyTimes();
    replay(interfaceService);
    TestPacketService packetService = new TestPacketService();
    // Run the test
    hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService, deviceService);
    hostMonitor.addMonitoringFor(TARGET_IPV4_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(Ethernet.VLAN_UNTAGGED, eth.getVlanID());
    ARP arp = (ARP) eth.getPayload();
    assertArrayEquals(SOURCE_IPV4_ADDR.toOctets(), arp.getSenderProtocolAddress());
    assertArrayEquals(sourceMac.toBytes(), arp.getSenderHardwareAddress());
    assertArrayEquals(TARGET_IPV4_ADDR.toOctets(), arp.getTargetProtocolAddress());
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) 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) PortNumber(org.onosproject.net.PortNumber) Interface(org.onosproject.net.intf.Interface) ARP(org.onlab.packet.ARP) Test(org.junit.Test)

Example 38 with Instruction

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

the class HostMonitorTest method testMonitorIpv4HostDoesNotExistWithVlan.

@Test
public void testMonitorIpv4HostDoesNotExistWithVlan() 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_IPV4_ADDR)).andReturn(Collections.emptySet()).anyTimes();
    replay(hostManager);
    InterfaceService interfaceService = createMock(InterfaceService.class);
    expect(interfaceService.getMatchingInterfaces(TARGET_IPV4_ADDR)).andReturn(Collections.singleton(new Interface(Interface.NO_INTERFACE_NAME, cp, Collections.singletonList(IA1), sourceMac, VlanId.vlanId(vlan)))).anyTimes();
    replay(interfaceService);
    TestPacketService packetService = new TestPacketService();
    // Run the test
    hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService, deviceService);
    hostMonitor.addMonitoringFor(TARGET_IPV4_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());
    ARP arp = (ARP) eth.getPayload();
    assertArrayEquals(SOURCE_IPV4_ADDR.toOctets(), arp.getSenderProtocolAddress());
    assertArrayEquals(sourceMac.toBytes(), arp.getSenderHardwareAddress());
    assertArrayEquals(TARGET_IPV4_ADDR.toOctets(), arp.getTargetProtocolAddress());
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) 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) PortNumber(org.onosproject.net.PortNumber) Interface(org.onosproject.net.intf.Interface) ARP(org.onlab.packet.ARP) Test(org.junit.Test)

Example 39 with Instruction

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

the class IntentJsonMatcher method matchConnectivityIntent.

/**
 * Matches the JSON representation of a connectivity intent. Calls the
 * matcher for the connectivity intent subtype.
 *
 * @param jsonIntent JSON representation of the intent
 * @param description Description object used for recording errors
 * @return true if the JSON matches the intent, false otherwise
 */
private boolean matchConnectivityIntent(JsonNode jsonIntent, Description description) {
    final ConnectivityIntent connectivityIntent = (ConnectivityIntent) intent;
    // check selector
    final JsonNode jsonSelector = jsonIntent.get("selector");
    final TrafficSelector selector = connectivityIntent.selector();
    final Set<Criterion> criteria = selector.criteria();
    final JsonNode jsonCriteria = jsonSelector.get("criteria");
    if (jsonCriteria.size() != criteria.size()) {
        description.appendText("size of criteria array is " + Integer.toString(jsonCriteria.size()));
        return false;
    }
    for (Criterion criterion : criteria) {
        boolean criterionFound = false;
        for (int criterionIndex = 0; criterionIndex < jsonCriteria.size(); criterionIndex++) {
            final CriterionJsonMatcher criterionMatcher = CriterionJsonMatcher.matchesCriterion(criterion);
            if (criterionMatcher.matches(jsonCriteria.get(criterionIndex))) {
                criterionFound = true;
                break;
            }
        }
        if (!criterionFound) {
            description.appendText("criterion not found " + criterion.toString());
            return false;
        }
    }
    // check treatment
    final JsonNode jsonTreatment = jsonIntent.get("treatment");
    final TrafficTreatment treatment = connectivityIntent.treatment();
    final List<Instruction> instructions = treatment.immediate();
    final JsonNode jsonInstructions = jsonTreatment.get("instructions");
    if (jsonInstructions.size() != instructions.size()) {
        description.appendText("size of instructions array is " + Integer.toString(jsonInstructions.size()));
        return false;
    }
    for (Instruction instruction : instructions) {
        boolean instructionFound = false;
        for (int instructionIndex = 0; instructionIndex < jsonInstructions.size(); instructionIndex++) {
            final InstructionJsonMatcher instructionMatcher = InstructionJsonMatcher.matchesInstruction(instruction);
            if (instructionMatcher.matches(jsonInstructions.get(instructionIndex))) {
                instructionFound = true;
                break;
            }
        }
        if (!instructionFound) {
            description.appendText("instruction not found " + instruction.toString());
            return false;
        }
    }
    // Check constraints
    final JsonNode jsonConstraints = jsonIntent.get("constraints");
    if (connectivityIntent.constraints() != null) {
        if (connectivityIntent.constraints().size() != jsonConstraints.size()) {
            description.appendText("constraints array size was " + Integer.toString(jsonConstraints.size()));
            return false;
        }
        for (final Constraint constraint : connectivityIntent.constraints()) {
            boolean constraintFound = false;
            for (int constraintIndex = 0; constraintIndex < jsonConstraints.size(); constraintIndex++) {
                final JsonNode value = jsonConstraints.get(constraintIndex);
                if (matchConstraint(constraint, value)) {
                    constraintFound = true;
                }
            }
            if (!constraintFound) {
                final String constraintString = constraint.toString();
                description.appendText("constraint missing " + constraintString);
                return false;
            }
        }
    } else if (jsonConstraints.size() != 0) {
        description.appendText("constraint array not empty");
        return false;
    }
    if (connectivityIntent instanceof HostToHostIntent) {
        return matchHostToHostIntent(jsonIntent, description);
    } else if (connectivityIntent instanceof PointToPointIntent) {
        return matchPointToPointIntent(jsonIntent, description);
    } else {
        description.appendText("class of connectivity intent is unknown");
        return false;
    }
}
Also used : WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) LinkTypeConstraint(org.onosproject.net.intent.constraint.LinkTypeConstraint) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) JsonNode(com.fasterxml.jackson.databind.JsonNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instruction(org.onosproject.net.flow.instructions.Instruction) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) ConnectPoint(org.onosproject.net.ConnectPoint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) LinkTypeConstraint(org.onosproject.net.intent.constraint.LinkTypeConstraint) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector)

Example 40 with Instruction

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

the class TrafficTreatmentCodecTest method testTrafficTreatmentEncode.

/**
 * Tests encoding of a traffic treatment object.
 */
@Test
public void testTrafficTreatmentEncode() {
    Instruction output = Instructions.createOutput(PortNumber.portNumber(0));
    Instruction modL2Src = Instructions.modL2Src(MacAddress.valueOf("11:22:33:44:55:66"));
    Instruction modL2Dst = Instructions.modL2Dst(MacAddress.valueOf("44:55:66:77:88:99"));
    MeterId meterId = MeterId.meterId(1);
    Instruction meter = Instructions.meterTraffic(meterId);
    Instruction transition = Instructions.transition(1);
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    TrafficTreatment treatment = tBuilder.add(output).add(modL2Src).add(modL2Dst).add(meter).add(transition).build();
    ObjectNode treatmentJson = trafficTreatmentCodec.encode(treatment, context);
    assertThat(treatmentJson, TrafficTreatmentJsonMatcher.matchesTrafficTreatment(treatment));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Instruction(org.onosproject.net.flow.instructions.Instruction) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) MeterId(org.onosproject.net.meter.MeterId) Test(org.junit.Test)

Aggregations

Instruction (org.onosproject.net.flow.instructions.Instruction)104 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)59 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)48 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)44 Criterion (org.onosproject.net.flow.criteria.Criterion)42 TrafficSelector (org.onosproject.net.flow.TrafficSelector)34 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)33 Instructions (org.onosproject.net.flow.instructions.Instructions)33 OutputInstruction (org.onosproject.net.flow.instructions.Instructions.OutputInstruction)32 L3ModificationInstruction (org.onosproject.net.flow.instructions.L3ModificationInstruction)32 PortNumber (org.onosproject.net.PortNumber)30 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)28 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)27 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)26 VlanId (org.onlab.packet.VlanId)25 DeviceId (org.onosproject.net.DeviceId)25 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)25 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)25 FlowRule (org.onosproject.net.flow.FlowRule)24 Group (org.onosproject.net.group.Group)23