use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.
the class DefaultCheckLoop method processOneOutputInstruction.
/**
* 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;
}
use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction in project onos by opennetworkinglab.
the class InstructionJsonMatcher method matchOutputInstruction.
// TODO: need to add matchModVlanHeaderInstruction
/**
* Matches the contents of an output instruction.
*
* @param instructionJson JSON instruction to match
* @param description Description object used for recording errors
* @return true if contents match, false otherwise
*/
private boolean matchOutputInstruction(JsonNode instructionJson, Description description) {
final String jsonType = instructionJson.get("type").textValue();
OutputInstruction instructionToMatch = (OutputInstruction) instruction;
if (!instructionToMatch.type().name().equals(jsonType)) {
description.appendText("type was " + jsonType);
return false;
}
if (instructionJson.get("port").isLong() || instructionJson.get("port").isInt()) {
final long jsonPort = instructionJson.get("port").asLong();
if (instructionToMatch.port().toLong() != (jsonPort)) {
description.appendText("port was " + jsonPort);
return false;
}
} else if (instructionJson.get("port").isTextual()) {
final String jsonPort = instructionJson.get("port").textValue();
if (!instructionToMatch.port().toString().equals(jsonPort)) {
description.appendText("port was " + jsonPort);
return false;
}
} else {
final String jsonPort = instructionJson.get("port").toString();
description.appendText("Unmatching types ");
description.appendText("instructionToMatch " + instructionToMatch.port().toString());
description.appendText("jsonPort " + jsonPort);
}
return true;
}
use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction 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());
}
use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction 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());
}
use of org.onosproject.net.flow.instructions.Instructions.OutputInstruction 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());
}
Aggregations