use of org.onosproject.net.packet.OutboundPacket in project onos by opennetworkinglab.
the class SdnIpReactiveRouting method forwardPacketToDst.
/**
* Emits the specified packet onto the network.
*
* @param context the packet context
* @param connectPoint the connect point where the packet should be
* sent out
*/
private void forwardPacketToDst(PacketContext context, ConnectPoint connectPoint) {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build();
OutboundPacket packet = new DefaultOutboundPacket(connectPoint.deviceId(), treatment, context.inPacket().unparsed());
packetService.emit(packet);
log.trace("sending packet: {}", packet);
}
use of org.onosproject.net.packet.OutboundPacket in project onos by opennetworkinglab.
the class VirtualNetworkPacketManagerTest method emitTest.
/**
* Tests the correct usage of emit() for a outbound packet.
*/
@Test
public void emitTest() {
OutboundPacket packet = new DefaultOutboundPacket(VDID1, DefaultTrafficTreatment.emptyTreatment(), ByteBuffer.allocate(5));
packetManager1.emit(packet);
assertEquals("Packet not emitted correctly", packet, emittedPacket);
}
use of org.onosproject.net.packet.OutboundPacket in project onos by opennetworkinglab.
the class VirtualNetworkPacketManagerWithDistStoreTest method emit2Test.
/**
* Tests the correct usage of emit() for a outbound packet - master of packet's
* sendThrough is not local node.
*/
@Test
@Ignore("Ignore until there is MastershipService support for virtual devices")
public void emit2Test() {
OutboundPacket packet = new DefaultOutboundPacket(VDID2, DefaultTrafficTreatment.emptyTreatment(), ByteBuffer.allocate(5));
packetManager1.emit(packet);
assertNull("Packet should not have been emmitted", emittedPacket);
}
use of org.onosproject.net.packet.OutboundPacket in project onos by opennetworkinglab.
the class DefaultVirtualPacketProvider method devirtualize.
/**
* Translate the requested virtual outbound packet into
* a set of physical OutboundPacket.
* See {@link org.onosproject.net.packet.OutboundPacket}
*
* @param packet an OutboundPacket to be translated
* @return a set of de-virtualized (physical) OutboundPacket
*/
private Set<OutboundPacket> devirtualize(NetworkId networkId, OutboundPacket packet) {
Set<OutboundPacket> outboundPackets = new HashSet<>();
Set<VirtualPort> vPorts = vnaService.getVirtualPorts(networkId, packet.sendThrough());
TrafficTreatment.Builder commonTreatmentBuilder = DefaultTrafficTreatment.builder();
packet.treatment().allInstructions().stream().filter(i -> i.type() != Instruction.Type.OUTPUT).forEach(i -> commonTreatmentBuilder.add(i));
TrafficTreatment commonTreatment = commonTreatmentBuilder.build();
PortNumber vOutPortNum = packet.treatment().allInstructions().stream().filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).findFirst().get();
if (!vOutPortNum.isLogical()) {
Optional<ConnectPoint> optionalCpOut = vPorts.stream().filter(v -> v.number().equals(vOutPortNum)).map(v -> v.realizedBy()).findFirst();
if (!optionalCpOut.isPresent()) {
log.warn("Port {} is not realized yet, in Network {}, Device {}", vOutPortNum, networkId, packet.sendThrough());
return outboundPackets;
}
ConnectPoint egressPoint = optionalCpOut.get();
TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(egressPoint.port()).build();
OutboundPacket outboundPacket = new DefaultOutboundPacket(egressPoint.deviceId(), treatment, packet.data());
outboundPackets.add(outboundPacket);
} else {
if (vOutPortNum == PortNumber.FLOOD) {
for (VirtualPort outPort : vPorts) {
ConnectPoint cpOut = outPort.realizedBy();
if (cpOut != null) {
TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(cpOut.port()).build();
OutboundPacket outboundPacket = new DefaultOutboundPacket(cpOut.deviceId(), treatment, packet.data());
outboundPackets.add(outboundPacket);
} else {
log.warn("Port {} is not realized yet, in Network {}, Device {}", outPort.number(), networkId, packet.sendThrough());
}
}
}
}
return outboundPackets;
}
use of org.onosproject.net.packet.OutboundPacket 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