Search in sources :

Example 26 with OutboundPacket

use of org.onosproject.net.packet.OutboundPacket in project onos by opennetworkinglab.

the class HostMonitor method sendProbe.

public void sendProbe(ConnectPoint connectPoint, IpAddress targetIp, IpAddress sourceIp, MacAddress sourceMac, VlanId vlan) {
    log.debug("Sending probe for target:{} out of intf:{} vlan:{}", targetIp, connectPoint, vlan);
    Ethernet probePacket;
    if (targetIp.isIp4()) {
        // IPv4: Use ARP
        probePacket = buildArpRequest(targetIp, sourceIp, sourceMac, vlan);
    } else {
        // IPv6: Use Neighbor Discovery. According to the NDP protocol,
        // we should use the solicitation node address as IPv6 destination
        // and the multicast mac address as Ethernet destination.
        byte[] destIp = IPv6.getSolicitNodeAddress(targetIp.toOctets());
        probePacket = NeighborSolicitation.buildNdpSolicit(targetIp.getIp6Address(), sourceIp.getIp6Address(), Ip6Address.valueOf(destIp), sourceMac, MacAddress.valueOf(IPv6.getMCastMacAddress(destIp)), vlan);
    }
    if (probePacket == null) {
        log.warn("Not able to build the probe packet");
        return;
    }
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build();
    OutboundPacket outboundPacket = new DefaultOutboundPacket(connectPoint.deviceId(), treatment, ByteBuffer.wrap(probePacket.serialize()));
    packetService.emit(outboundPacket);
}
Also used : Ethernet(org.onlab.packet.Ethernet) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket)

Example 27 with OutboundPacket

use of org.onosproject.net.packet.OutboundPacket in project onos by opennetworkinglab.

the class DefaultVirtualPacketProvider method devirtualizeContext.

/**
 * Translate the requested virtual packet context into
 * a set of physical outbound packets.
 *
 * @param context A handled virtual packet context
 */
private Set<OutboundPacket> devirtualizeContext(VirtualPacketContext context) {
    Set<OutboundPacket> outboundPackets = new HashSet<>();
    NetworkId networkId = context.networkId();
    TrafficTreatment vTreatment = context.treatmentBuilder().build();
    DeviceId sendThrough = context.outPacket().sendThrough();
    Set<VirtualPort> vPorts = vnaService.getVirtualPorts(networkId, sendThrough);
    PortNumber vOutPortNum = vTreatment.allInstructions().stream().filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).findFirst().get();
    TrafficTreatment.Builder commonTreatmentBuilder = DefaultTrafficTreatment.builder();
    vTreatment.allInstructions().stream().filter(i -> i.type() != Instruction.Type.OUTPUT).forEach(i -> commonTreatmentBuilder.add(i));
    TrafficTreatment commonTreatment = commonTreatmentBuilder.build();
    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, sendThrough);
            return outboundPackets;
        }
        ConnectPoint egressPoint = optionalCpOut.get();
        TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(egressPoint.port()).build();
        OutboundPacket outboundPacket = new DefaultOutboundPacket(egressPoint.deviceId(), treatment, context.outPacket().data());
        outboundPackets.add(outboundPacket);
    } else {
        if (vOutPortNum == PortNumber.FLOOD) {
            Set<VirtualPort> outPorts = vPorts.stream().filter(vp -> !vp.number().isLogical()).filter(vp -> vp.number() != context.inPacket().receivedFrom().port()).collect(Collectors.toSet());
            for (VirtualPort outPort : outPorts) {
                ConnectPoint cpOut = outPort.realizedBy();
                if (cpOut != null) {
                    TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(cpOut.port()).build();
                    OutboundPacket outboundPacket = new DefaultOutboundPacket(cpOut.deviceId(), treatment, context.outPacket().data());
                    outboundPackets.add(outboundPacket);
                } else {
                    log.warn("Port {} is not realized yet, in Network {}, Device {}", outPort.number(), networkId, sendThrough);
                }
            }
        }
    }
    return outboundPackets;
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) VirtualNetworkEvent(org.onosproject.incubator.net.virtual.VirtualNetworkEvent) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) ComponentContext(org.osgi.service.component.ComponentContext) VirtualPacketProviderService(org.onosproject.incubator.net.virtual.provider.VirtualPacketProviderService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet) Ethernet(org.onlab.packet.Ethernet) Component(org.osgi.service.component.annotations.Component) VirtualPacketContext(org.onosproject.incubator.net.virtual.VirtualPacketContext) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ApplicationId(org.onosproject.core.ApplicationId) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Activate(org.osgi.service.component.annotations.Activate) VirtualProviderRegistryService(org.onosproject.incubator.net.virtual.provider.VirtualProviderRegistryService) TenantId(org.onosproject.net.TenantId) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Deactivate(org.osgi.service.component.annotations.Deactivate) Instruction(org.onosproject.net.flow.instructions.Instruction) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Set(java.util.Set) PacketService(org.onosproject.net.packet.PacketService) ProviderId(org.onosproject.net.provider.ProviderId) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) VirtualPacketProvider(org.onosproject.incubator.net.virtual.provider.VirtualPacketProvider) VirtualNetworkListener(org.onosproject.incubator.net.virtual.VirtualNetworkListener) AbstractVirtualProvider(org.onosproject.incubator.net.virtual.provider.AbstractVirtualProvider) InboundPacket(org.onosproject.net.packet.InboundPacket) PacketContext(org.onosproject.net.packet.PacketContext) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) VirtualNetworkAdminService(org.onosproject.incubator.net.virtual.VirtualNetworkAdminService) Optional(java.util.Optional) PacketPriority(org.onosproject.net.packet.PacketPriority) Reference(org.osgi.service.component.annotations.Reference) DeviceId(org.onosproject.net.DeviceId) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Dictionary(java.util.Dictionary) DeviceId(org.onosproject.net.DeviceId) Instructions(org.onosproject.net.flow.instructions.Instructions) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) PortNumber(org.onosproject.net.PortNumber) HashSet(java.util.HashSet)

Example 28 with OutboundPacket

use of org.onosproject.net.packet.OutboundPacket in project onos by opennetworkinglab.

the class NeighbourResolutionManagerTest method context.

/**
 * Creates a packet context for the given packet coming in the given port.
 *
 * @param packet packet to wrap in a packet context
 * @param inPort input port of the packet
 * @return packet context
 */
private static PacketContext context(Ethernet packet, ConnectPoint inPort) {
    InboundPacket inboundPacket = new DefaultInboundPacket(inPort, packet, null);
    OutboundPacket outboundPacket = new DefaultOutboundPacket(null, null, null);
    return new PacketContextAdapter(0, inboundPacket, outboundPacket, false);
}
Also used : DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) InboundPacket(org.onosproject.net.packet.InboundPacket) PacketContextAdapter(org.onosproject.net.packet.PacketContextAdapter) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket)

Example 29 with OutboundPacket

use of org.onosproject.net.packet.OutboundPacket in project onos by opennetworkinglab.

the class PacketManagerTest method packetProviderfallbackBasics.

/**
 * Tests the correct usage of fallback driver provider for packets.
 */
@Test
public void packetProviderfallbackBasics() {
    OutboundPacket packet = new DefaultOutboundPacket(FOO_DID, DefaultTrafficTreatment.emptyTreatment(), ByteBuffer.allocate(5));
    mgr.emit(packet);
    assertEquals("Packet not emitted correctly", packet, emittedPacket);
}
Also used : DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Test(org.junit.Test)

Example 30 with OutboundPacket

use of org.onosproject.net.packet.OutboundPacket in project onos by opennetworkinglab.

the class DefaultVirtualPacketProviderTest method devirtualizePacket.

/**
 * Test the virtual outbound packet is delivered to a proper (physical)
 *  device.
 */
@Test
public void devirtualizePacket() {
    TrafficTreatment tr = DefaultTrafficTreatment.builder().setOutput(VPORT_NUM1).build();
    ByteBuffer data = ByteBuffer.wrap("abc".getBytes());
    OutboundPacket vOutPacket = new DefaultOutboundPacket(VDID, tr, data);
    virtualProvider.emit(VNET_ID, vOutPacket);
    assertEquals("The count should be 1", 1, testPacketService.getRequestedPacketCount());
    OutboundPacket pOutPacket = testPacketService.getRequestedPacket(0);
    assertEquals("The packet should be requested on DEV1", DID1, pOutPacket.sendThrough());
    PortNumber outPort = pOutPacket.treatment().allInstructions().stream().filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> (Instructions.OutputInstruction) i).map(i -> i.port()).findFirst().get();
    assertEquals("The packet should be out at PORT1 of DEV1", PORT_NUM1, outPort);
}
Also used : DefaultApplicationId(org.onosproject.core.DefaultApplicationId) AbstractVirtualProviderService(org.onosproject.incubator.net.virtual.provider.AbstractVirtualProviderService) DefaultPacketContext(org.onosproject.net.packet.DefaultPacketContext) PortNumber(org.onosproject.net.PortNumber) DefaultDevice(org.onosproject.net.DefaultDevice) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) Port(org.onosproject.net.Port) After(org.junit.After) ApplicationId(org.onosproject.core.ApplicationId) DefaultLink(org.onosproject.net.DefaultLink) ImmutableSet(com.google.common.collect.ImmutableSet) DefaultPort(org.onosproject.net.DefaultPort) Device(org.onosproject.net.Device) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Set(java.util.Set) VirtualPacketProvider(org.onosproject.incubator.net.virtual.provider.VirtualPacketProvider) List(java.util.List) InboundPacket(org.onosproject.net.packet.InboundPacket) PacketContext(org.onosproject.net.packet.PacketContext) DefaultVirtualDevice(org.onosproject.incubator.net.virtual.DefaultVirtualDevice) CoreServiceAdapter(org.onosproject.core.CoreServiceAdapter) DeviceId(org.onosproject.net.DeviceId) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort) VirtualPacketProviderService(org.onosproject.incubator.net.virtual.provider.VirtualPacketProviderService) VirtualNetworkAdminServiceAdapter(org.onosproject.incubator.net.virtual.VirtualNetworkAdminServiceAdapter) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OutboundPacket(org.onosproject.net.packet.OutboundPacket) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) PacketServiceAdapter(org.onosproject.net.packet.PacketServiceAdapter) LinkedList(java.util.LinkedList) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Before(org.junit.Before) TenantId(org.onosproject.net.TenantId) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instructions(org.onosproject.net.flow.instructions.Instructions) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Assert.assertEquals(org.junit.Assert.assertEquals) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PortNumber(org.onosproject.net.PortNumber) ByteBuffer(java.nio.ByteBuffer) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Test(org.junit.Test)

Aggregations

OutboundPacket (org.onosproject.net.packet.OutboundPacket)46 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)35 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)29 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)25 Ethernet (org.onlab.packet.Ethernet)20 Test (org.junit.Test)17 ConnectPoint (org.onosproject.net.ConnectPoint)16 PortNumber (org.onosproject.net.PortNumber)15 DeviceId (org.onosproject.net.DeviceId)12 ByteBuffer (java.nio.ByteBuffer)11 Port (org.onosproject.net.Port)9 InboundPacket (org.onosproject.net.packet.InboundPacket)9 PiPacketOperation (org.onosproject.net.pi.runtime.PiPacketOperation)9 ImmutableList (com.google.common.collect.ImmutableList)8 Instruction (org.onosproject.net.flow.instructions.Instruction)8 DefaultInboundPacket (org.onosproject.net.packet.DefaultInboundPacket)8 PiPacketMetadata (org.onosproject.net.pi.runtime.PiPacketMetadata)8 Optional (java.util.Optional)7 Device (org.onosproject.net.Device)7 Interface (org.onosproject.net.intf.Interface)6