Search in sources :

Example 16 with InboundPacket

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

the class OpenstackRoutingSnatHandler method processSnatPacket.

private void processSnatPacket(PacketContext context, Ethernet eth) {
    if (getStatefulSnatFlag()) {
        return;
    }
    IPv4 iPacket = (IPv4) eth.getPayload();
    InboundPacket packetIn = context.inPacket();
    int patPort = getPortNum();
    InstancePort srcInstPort = instancePortService.instancePort(eth.getSourceMAC());
    if (srcInstPort == null) {
        log.error(ERR_PACKET_IN + "source host(MAC:{}) does not exist", eth.getSourceMAC());
        return;
    }
    IpAddress srcIp = IpAddress.valueOf(iPacket.getSourceAddress());
    Subnet srcSubnet = getSourceSubnet(srcInstPort, srcIp);
    Router osRouter = getRouterFromSubnet(srcSubnet, osRouterService);
    if (osRouter == null || osRouter.getExternalGatewayInfo() == null) {
        // this router does not have external connectivity
        log.warn("No router is associated with the given subnet {}", srcSubnet);
        return;
    }
    IpAddress externalGatewayIp = externalGatewayIpSnatEnabled(osRouter, osNetworkAdminService);
    if (externalGatewayIp == null) {
        return;
    }
    ExternalPeerRouter externalPeerRouter = externalPeerRouterFromSubnet(srcSubnet, osRouterService, osNetworkService);
    if (externalPeerRouter == null) {
        return;
    }
    populateSnatFlowRules(context.inPacket(), srcInstPort, TpPort.tpPort(patPort), externalGatewayIp, externalPeerRouter);
    packetOut(eth.duplicate(), packetIn.receivedFrom().deviceId(), patPort, externalGatewayIp, externalPeerRouter);
}
Also used : ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) IPv4(org.onlab.packet.IPv4) InboundPacket(org.onosproject.net.packet.InboundPacket) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) Router(org.openstack4j.model.network.Router) IpAddress(org.onlab.packet.IpAddress) OpenstackNetworkingUtil.externalPeerRouterFromSubnet(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.externalPeerRouterFromSubnet) Subnet(org.openstack4j.model.network.Subnet) OpenstackNetworkingUtil.getRouterFromSubnet(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getRouterFromSubnet)

Example 17 with InboundPacket

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

the class OpenstackRoutingSnatIcmpHandlerTest method sendPacket.

private void sendPacket(Ethernet ethernet) {
    final ByteBuffer byteBuffer = ByteBuffer.wrap(ethernet.serialize());
    InboundPacket inPacket = new DefaultInboundPacket(connectPoint(srcDeviceId1.toString(), Integer.parseInt(srcPortNum1.toString())), ethernet, byteBuffer);
    PacketContext context = new TestPacketContext(127L, inPacket, null, false);
    packetProcessor.process(context);
}
Also used : DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) InboundPacket(org.onosproject.net.packet.InboundPacket) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) DefaultPacketContext(org.onosproject.net.packet.DefaultPacketContext) PacketContext(org.onosproject.net.packet.PacketContext) ByteBuffer(java.nio.ByteBuffer)

Example 18 with InboundPacket

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

the class OpenstackSwitchingArpHandlerTest method sendPacket.

/**
 * Sends an Ethernet packet to the process method of the Packet processor.
 *
 * @param ethernet Ethernet packet
 */
private void sendPacket(Ethernet ethernet) {
    final ByteBuffer byteBuffer = ByteBuffer.wrap(ethernet.serialize());
    InboundPacket inPacket = new DefaultInboundPacket(connectPoint("1", 1), ethernet, byteBuffer);
    PacketContext context = new TestPacketContext(127L, inPacket, null, false);
    packetProcessor.process(context);
}
Also used : DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) InboundPacket(org.onosproject.net.packet.InboundPacket) DefaultPacketContext(org.onosproject.net.packet.DefaultPacketContext) PacketContext(org.onosproject.net.packet.PacketContext) ByteBuffer(java.nio.ByteBuffer)

Example 19 with InboundPacket

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

the class OpenstackSwitchingDhcpHandlerTest method sendPacket.

/**
 * Sends an Ethernet packet to the process method of the Packet Processor.
 *
 * @param ethernet Ethernet packet
 */
private void sendPacket(Ethernet ethernet) {
    final ByteBuffer byteBuffer = ByteBuffer.wrap(ethernet.serialize());
    InboundPacket inPacket = new DefaultInboundPacket(connectPoint("1", 1), ethernet, byteBuffer);
    PacketContext context = new TestPacketContext(127L, inPacket, null, false);
    packetProcessor.process(context);
}
Also used : DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) InboundPacket(org.onosproject.net.packet.InboundPacket) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) DefaultPacketContext(org.onosproject.net.packet.DefaultPacketContext) PacketContext(org.onosproject.net.packet.PacketContext) ByteBuffer(java.nio.ByteBuffer)

Example 20 with InboundPacket

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

the class MQUtil method json.

/**
 * Returns a JSON representation of the given packet context.
 *
 * @param  context the packet context
 * @return         the inbound packetjson message
 */
public static JsonObject json(PacketContext context) {
    JsonObject jo = new JsonObject();
    InboundPacket pkt = context.inPacket();
    // parse connection host
    jo.addProperty(SWITCH_ID, pkt.receivedFrom().deviceId().toString());
    jo.addProperty(IN_PORT, pkt.receivedFrom().port().name());
    jo.addProperty(LOGICAL, pkt.receivedFrom().port().isLogical());
    jo.addProperty(RECEIVED, new Date(context.time()).toString());
    jo.addProperty(MSG_TYPE, PKT_TYPE);
    // parse ethernet
    jo.addProperty(SUB_MSG_TYPE, EthType.EtherType.lookup(pkt.parsed().getEtherType()).name());
    jo.addProperty(ETH_TYPE, pkt.parsed().getEtherType());
    jo.addProperty(SRC_MAC_ADDR, pkt.parsed().getSourceMAC().toString());
    jo.addProperty(DEST_MAC_ADDR, pkt.parsed().getDestinationMAC().toString());
    jo.addProperty(VLAN_ID, pkt.parsed().getVlanID());
    jo.addProperty(B_CAST, pkt.parsed().isBroadcast());
    jo.addProperty(M_CAST, pkt.parsed().isMulticast());
    jo.addProperty(PAD, pkt.parsed().isPad());
    jo.addProperty(PRIORITY_CODE, pkt.parsed().getPriorityCode());
    // parse bytebuffer
    jo.addProperty(DATA_LEN, pkt.unparsed().array().length);
    jo.addProperty(PAYLOAD, pkt.unparsed().asCharBuffer().toString());
    return jo;
}
Also used : InboundPacket(org.onosproject.net.packet.InboundPacket) JsonObject(com.google.gson.JsonObject) Date(java.util.Date)

Aggregations

InboundPacket (org.onosproject.net.packet.InboundPacket)28 DefaultInboundPacket (org.onosproject.net.packet.DefaultInboundPacket)19 Ethernet (org.onlab.packet.Ethernet)18 ByteBuffer (java.nio.ByteBuffer)12 ConnectPoint (org.onosproject.net.ConnectPoint)10 PiPacketOperation (org.onosproject.net.pi.runtime.PiPacketOperation)10 PortNumber (org.onosproject.net.PortNumber)9 PiPacketMetadata (org.onosproject.net.pi.runtime.PiPacketMetadata)9 DeserializationException (org.onlab.packet.DeserializationException)7 OutboundPacket (org.onosproject.net.packet.OutboundPacket)7 PacketContext (org.onosproject.net.packet.PacketContext)7 Test (org.junit.Test)6 DeviceId (org.onosproject.net.DeviceId)6 Port (org.onosproject.net.Port)6 DefaultPacketContext (org.onosproject.net.packet.DefaultPacketContext)6 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 String.format (java.lang.String.format)5 Collection (java.util.Collection)5 List (java.util.List)5