Search in sources :

Example 41 with DefaultOutboundPacket

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

the class TunnellingConnectivityManager method forward.

/**
 * Forwards a BGP packet to another connect point.
 *
 * @param context the packet context of the incoming packet
 */
private void forward(PacketContext context) {
    ConnectPoint outputPort = null;
    IPv4 ipv4 = (IPv4) context.inPacket().parsed().getPayload();
    IpAddress dstAddress = IpAddress.valueOf(ipv4.getDestinationAddress());
    if (context.inPacket().receivedFrom().equals(bgpSpeaker.connectPoint())) {
        if (bgpSpeaker.peers().contains(dstAddress)) {
            Interface intf = interfaceService.getMatchingInterface(dstAddress);
            if (intf != null) {
                outputPort = intf.connectPoint();
            }
        }
    } else {
        Set<Interface> interfaces = interfaceService.getInterfacesByPort(context.inPacket().receivedFrom());
        if (interfaces.stream().flatMap(intf -> intf.ipAddressesList().stream()).anyMatch(ia -> ia.ipAddress().equals(dstAddress))) {
            outputPort = bgpSpeaker.connectPoint();
        }
    }
    if (outputPort != null) {
        TrafficTreatment t = DefaultTrafficTreatment.builder().setOutput(outputPort.port()).build();
        OutboundPacket o = new DefaultOutboundPacket(outputPort.deviceId(), t, context.inPacket().unparsed());
        packetService.emit(o);
    }
}
Also used : Interface(org.onosproject.net.intf.Interface) InterfaceService(org.onosproject.net.intf.InterfaceService) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) TCP(org.onlab.packet.TCP) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ApplicationId(org.onosproject.core.ApplicationId) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) TpPort(org.onlab.packet.TpPort) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Set(java.util.Set) PacketService(org.onosproject.net.packet.PacketService) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) BgpConfig(org.onosproject.routing.config.BgpConfig) IPv4(org.onlab.packet.IPv4) PacketContext(org.onosproject.net.packet.PacketContext) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) IPv4(org.onlab.packet.IPv4) IpAddress(org.onlab.packet.IpAddress) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) Interface(org.onosproject.net.intf.Interface) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket)

Example 42 with DefaultOutboundPacket

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

the class IcmpHandler method sendPacketOut.

private void sendPacketOut(ConnectPoint outport, Ethernet payload) {
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outport.port()).build();
    OutboundPacket packet = new DefaultOutboundPacket(outport.deviceId(), treatment, ByteBuffer.wrap(payload.serialize()));
    packetService.emit(packet);
}
Also used : DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket)

Example 43 with DefaultOutboundPacket

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

the class FabricInterpreterTest method testMapOutboundPacketWithForwarding.

@Test
public void testMapOutboundPacketWithForwarding() throws Exception {
    PortNumber outputPort = PortNumber.TABLE;
    TrafficTreatment outputTreatment = DefaultTrafficTreatment.builder().setOutput(outputPort).build();
    ByteBuffer data = ByteBuffer.allocate(64);
    OutboundPacket outPkt = new DefaultOutboundPacket(DEVICE_ID, outputTreatment, data);
    Collection<PiPacketOperation> result = interpreter.mapOutboundPacket(outPkt);
    assertEquals(result.size(), 1);
    ImmutableList.Builder<PiPacketMetadata> builder = ImmutableList.builder();
    builder.add(PiPacketMetadata.builder().withId(FabricConstants.DO_FORWARDING).withValue(ImmutableByteSequence.copyFrom(1).fit(1)).build());
    PiPacketOperation expectedPktOp = PiPacketOperation.builder().withType(PiPacketOperationType.PACKET_OUT).withData(ImmutableByteSequence.copyFrom(data)).withMetadatas(builder.build()).build();
    assertEquals(expectedPktOp, result.iterator().next());
}
Also used : PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) ImmutableList(com.google.common.collect.ImmutableList) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ByteBuffer(java.nio.ByteBuffer) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Test(org.junit.Test)

Example 44 with DefaultOutboundPacket

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

the class FabricInterpreterTest method testMapOutboundPacketWithoutForwarding.

@Test
public void testMapOutboundPacketWithoutForwarding() throws Exception {
    PortNumber outputPort = PortNumber.portNumber(1);
    TrafficTreatment outputTreatment = DefaultTrafficTreatment.builder().setOutput(outputPort).build();
    ByteBuffer data = ByteBuffer.allocate(64);
    OutboundPacket outPkt = new DefaultOutboundPacket(DEVICE_ID, outputTreatment, data);
    Collection<PiPacketOperation> result = interpreter.mapOutboundPacket(outPkt);
    assertEquals(result.size(), 1);
    ImmutableList.Builder<PiPacketMetadata> builder = ImmutableList.builder();
    builder.add(PiPacketMetadata.builder().withId(FabricConstants.EGRESS_PORT).withValue(ImmutableByteSequence.copyFrom(outputPort.toLong()).fit(PORT_BITWIDTH)).build());
    PiPacketOperation expectedPktOp = PiPacketOperation.builder().withType(PiPacketOperationType.PACKET_OUT).withData(ImmutableByteSequence.copyFrom(data)).withMetadatas(builder.build()).build();
    assertEquals(expectedPktOp, result.iterator().next());
}
Also used : PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) ImmutableList(com.google.common.collect.ImmutableList) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ByteBuffer(java.nio.ByteBuffer) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Test(org.junit.Test)

Example 45 with DefaultOutboundPacket

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

the class KubevirtRoutingArpHandler method retrievePeerRouterMac.

/**
 * Triggers ARP request to retrieve the peer router mac address.
 *
 * @param router kubevirt router
 * @param peerRouterIp peer router IP address
 */
private void retrievePeerRouterMac(KubevirtRouter router, IpAddress peerRouterIp) {
    log.info("Sending ARP request to the peer router {} to retrieve the MAC address.", peerRouterIp.getIp4Address().toString());
    String routerSnatIp = router.external().keySet().stream().findAny().orElse(null);
    if (routerSnatIp == null) {
        return;
    }
    IpAddress sourceIp = IpAddress.valueOf(routerSnatIp);
    MacAddress sourceMac = DEFAULT_GATEWAY_MAC;
    Ethernet ethRequest = ARP.buildArpRequest(sourceMac.toBytes(), sourceIp.toOctets(), peerRouterIp.toOctets(), VlanId.NO_VID);
    KubevirtNode gatewayNode = kubevirtNodeService.node(router.electedGateway());
    if (gatewayNode == null) {
        return;
    }
    PortNumber externalPatchPortNum = KubevirtNetworkingUtil.externalPatchPortNum(deviceService, gatewayNode);
    if (externalPatchPortNum == null) {
        return;
    }
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(externalPatchPortNum).build();
    packetService.emit(new DefaultOutboundPacket(gatewayNode.intgBridge(), treatment, ByteBuffer.wrap(ethRequest.serialize())));
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) Ethernet(org.onlab.packet.Ethernet) IpAddress(org.onlab.packet.IpAddress) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) MacAddress(org.onlab.packet.MacAddress) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Aggregations

DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)53 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)42 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)41 OutboundPacket (org.onosproject.net.packet.OutboundPacket)32 Ethernet (org.onlab.packet.Ethernet)23 ByteBuffer (java.nio.ByteBuffer)12 ConnectPoint (org.onosproject.net.ConnectPoint)12 PortNumber (org.onosproject.net.PortNumber)11 IpAddress (org.onlab.packet.IpAddress)9 Test (org.junit.Test)8 DeviceId (org.onosproject.net.DeviceId)8 InboundPacket (org.onosproject.net.packet.InboundPacket)7 PacketContext (org.onosproject.net.packet.PacketContext)7 Set (java.util.Set)6 MacAddress (org.onlab.packet.MacAddress)6 ApplicationId (org.onosproject.core.ApplicationId)6 PacketProcessor (org.onosproject.net.packet.PacketProcessor)6 DefaultInboundPacket (org.onosproject.net.packet.DefaultInboundPacket)5 PacketService (org.onosproject.net.packet.PacketService)5 PiPacketOperation (org.onosproject.net.pi.runtime.PiPacketOperation)5