org.onosproject.net.packet.InboundPacket Java Examples

The following examples show how to use org.onosproject.net.packet.InboundPacket. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    IPv4 ipv4 = new IPv4();
    ipv4.setDestinationAddress("10.0.0.1");
    ipv4.setSourceAddress(IP_ADDRESS.toString());
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV4)
            .setVlanID(VLAN.toShort())
            .setSourceMACAddress(MAC)
            .setDestinationMACAddress(MacAddress.valueOf("00:00:00:00:00:01"))
            .setPayload(ipv4);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
                                                 portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
                                    ByteBuffer.wrap(eth.serialize()));
}
 
Example #2
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    IPv6 ipv6 = new IPv6();
    ipv6.setDestinationAddress(Ip6Address.valueOf("1000::1").toOctets());
    ipv6.setSourceAddress(IP2);
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV6)
            .setVlanID(VLAN.toShort())
            .setSourceMACAddress(MAC2)
            .setDestinationMACAddress(MacAddress.valueOf("00:00:00:00:00:01"))
            .setPayload(ipv6);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
                                                 portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
                                    ByteBuffer.wrap(eth.serialize()));
}
 
Example #3
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    IPv6 ipv6 = new IPv6();
    ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::1").toOctets());
    ipv6.setSourceAddress(IP2);
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV6)
            .setVlanID(VLAN.toShort())
            .setSourceMACAddress(MAC2.toBytes())
            .setDestinationMACAddress(MacAddress.valueOf("33:33:00:00:00:01"))
            .setPayload(ipv6);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
                                                 portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
                                    ByteBuffer.wrap(eth.serialize()));
}
 
Example #4
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    RouterAdvertisement ns = new RouterAdvertisement();
    ICMP6 icmp6 = new ICMP6();
    icmp6.setPayload(ns);
    IPv6 ipv6 = new IPv6();
    ipv6.setPayload(icmp6);
    ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::1").toOctets());
    ipv6.setSourceAddress(IP2);
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV6)
            .setVlanID(VLAN.toShort())
            .setSourceMACAddress(MAC2.toBytes())
            .setDestinationMACAddress(MacAddress.valueOf("33:33:00:00:00:01"))
            .setPayload(ipv6);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
                                                 portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
                                    ByteBuffer.wrap(eth.serialize()));
}
 
Example #5
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    RouterSolicitation ns = new RouterSolicitation();
    ICMP6 icmp6 = new ICMP6();
    icmp6.setPayload(ns);
    IPv6 ipv6 = new IPv6();
    ipv6.setPayload(icmp6);
    ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::2").toOctets());
    ipv6.setSourceAddress(IP2);
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV6)
            .setVlanID(VLAN.toShort())
            .setSourceMACAddress(MAC2.toBytes())
            .setDestinationMACAddress(MacAddress.valueOf("33:33:00:00:00:02"))
            .setPayload(ipv6);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
                                                 portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
                                    ByteBuffer.wrap(eth.serialize()));
}
 
Example #6
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    NeighborSolicitation ns = new NeighborSolicitation();
    ICMP6 icmp6 = new ICMP6();
    icmp6.setPayload(ns);
    IPv6 ipv6 = new IPv6();
    ipv6.setPayload(icmp6);
    ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::1").toOctets());
    ipv6.setSourceAddress(Ip6Address.valueOf("::").toOctets());
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV6)
            .setVlanID(VLAN.toShort())
            .setSourceMACAddress(MAC2.toBytes())
            .setDestinationMACAddress(BCMAC2)
            .setPayload(ipv6);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
                                                 portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
                                    ByteBuffer.wrap(eth.serialize()));
}
 
Example #7
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    NeighborSolicitation ns = new NeighborSolicitation();
    ICMP6 icmp6 = new ICMP6();
    icmp6.setPayload(ns);
    IPv6 ipv6 = new IPv6();
    ipv6.setPayload(icmp6);
    ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::1:ff00:0000").toOctets());
    ipv6.setSourceAddress(IP2);
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV6)
            .setVlanID(VLAN.toShort())
            .setSourceMACAddress(MAC2.toBytes())
            .setDestinationMACAddress(BCMAC2)
            .setPayload(ipv6);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
                                                 portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
                                    ByteBuffer.wrap(eth.serialize()));
}
 
Example #8
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    NeighborAdvertisement na = new NeighborAdvertisement();
    na.setTargetAddress(IP2);
    ICMP6 icmp6 = new ICMP6();
    icmp6.setPayload(na);
    IPv6 ipv6 = new IPv6();
    ipv6.setPayload(icmp6);
    ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::1").toOctets());
    ipv6.setSourceAddress(LLIP2);
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV6)
            .setVlanID(VLAN.toShort())
            .setSourceMACAddress(MAC2.toBytes())
            .setDestinationMACAddress(BCMAC2)
            .setPayload(ipv6);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
                                                 portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
                                    ByteBuffer.wrap(eth.serialize()));
}
 
Example #9
Source File: MQUtil.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #10
Source File: OpenstackRoutingSnatIcmpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void process(PacketContext context) {
    if (context.isHandled()) {
        return;
    }

    eventExecutor.execute(() -> {

        if (!isRelevantHelper(context)) {
            return;
        }

        InboundPacket pkt = context.inPacket();
        Ethernet ethernet = pkt.parsed();
        if (ethernet == null || ethernet.getEtherType() != Ethernet.TYPE_IPV4) {
            return;
        }

        IPv4 iPacket = (IPv4) ethernet.getPayload();

        if (iPacket.getProtocol() == IPv4.PROTOCOL_ICMP) {
            processIcmpPacket(context, ethernet);
        }
    });
}
 
Example #11
Source File: OpenstackRoutingArpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void process(PacketContext context) {
    if (context.isHandled()) {
        return;
    }

    InboundPacket pkt = context.inPacket();
    Ethernet ethernet = pkt.parsed();
    if (ethernet != null && ethernet.getEtherType() == Ethernet.TYPE_ARP) {
        eventExecutor.execute(() -> {

            if (!isRelevantHelper(context)) {
                return;
            }

            processArpPacket(context, ethernet);
        });
    }
}
 
Example #12
Source File: CastorArpManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void process(PacketContext context) {

    if (context.isHandled()) {
        return;
    }
    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();
    if (ethPkt == null) {
        return;
    }
    if (ethPkt.getEtherType() == TYPE_ARP) {
        //handle the arp packet.
        handlePacket(context);
    } else {
        return;
    }
}
 
Example #13
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    ARP arp = new ARP();
    arp.setSenderProtocolAddress(IP)
            .setSenderHardwareAddress(MAC.toBytes())
            .setTargetHardwareAddress(BCMAC.toBytes())
            .setTargetProtocolAddress(IP);

    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_ARP)
            .setVlanID(VLAN.toShort())
            .setSourceMACAddress(MAC.toBytes())
            .setDestinationMACAddress(BCMAC)
            .setPayload(arp);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
                                                 portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
                                    ByteBuffer.wrap(eth.serialize()));
}
 
Example #14
Source File: NetworkConfigLinksProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    ONOSLLDP lldp = ONOSLLDP.onosSecureLLDP(src.deviceId().toString(),
                                            new ChassisId(),
                                            (int) src.port().toLong(), "", "test-secret");

    Ethernet ethPacket = new Ethernet();
    ethPacket.setEtherType(Ethernet.TYPE_LLDP);
    ethPacket.setDestinationMACAddress(MacAddress.ONOS_LLDP);
    ethPacket.setPayload(lldp);
    ethPacket.setPad(true);

    ethPacket.setSourceMACAddress("DE:AD:BE:EF:BA:11");

    return new DefaultInboundPacket(dst, ethPacket,
                                    ByteBuffer.wrap(ethPacket.serialize()));

}
 
Example #15
Source File: LldpLinkProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    ONOSLLDP lldp = ONOSLLDP.onosSecureLLDP(deviceService.getDevice(DID1).id().toString(),
                                            device.chassisId(),
                                            (int) pd1.number().toLong(), "", "test");

    Ethernet ethPacket = new Ethernet();
    ethPacket.setEtherType(Ethernet.TYPE_LLDP);
    ethPacket.setDestinationMACAddress(MacAddress.ONOS_LLDP);
    ethPacket.setPayload(lldp);
    ethPacket.setPad(true);

    ethPacket.setSourceMACAddress("DE:AD:BE:EF:BA:11");

    ConnectPoint cp = new ConnectPoint(device.id(), pd3.number());

    return new DefaultInboundPacket(cp, ethPacket,
                                    ByteBuffer.wrap(ethPacket.serialize()));

}
 
Example #16
Source File: MQEventHandlerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    ONOSLLDP lldp = ONOSLLDP.onosSecureLLDP(deviceService.getDevice(DID1)
                                      .id().toString(),
                                            device.chassisId(),
                                            (int) pd1.number().toLong(), "", "test");

    Ethernet ethPacket = new Ethernet();
    ethPacket.setEtherType(Ethernet.TYPE_LLDP);
    ethPacket.setDestinationMACAddress(MacAddress.ONOS_LLDP);
    ethPacket.setPayload(lldp);
    ethPacket.setPad(true);

    ethPacket.setSourceMACAddress("DE:AD:BE:EF:BA:11");

    ConnectPoint cp = new ConnectPoint(device.id(), pd3.number());

    return new DefaultInboundPacket(cp, ethPacket,
                                    ByteBuffer.wrap(ethPacket
                                    .serialize()));

}
 
Example #17
Source File: RouterAdvertisementManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void process(PacketContext context) {
    if (context.isHandled()) {
        return;
    }

    // Ensure packet is IPv6 Solicited RA
    InboundPacket pkt = context.inPacket();
    Ethernet ethernet = pkt.parsed();
    if ((ethernet == null) || (ethernet.getEtherType() != Ethernet.TYPE_IPV6)) {
        return;
    }
    IPv6 ipv6Packet = (IPv6) ethernet.getPayload();
    if (ipv6Packet.getNextHeader() != IPv6.PROTOCOL_ICMP6) {
        return;
    }
    ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
    if (icmp6Packet.getIcmpType() != ICMP6.ROUTER_SOLICITATION) {
        return;
    }

    // Start solicited-RA handling thread
    SolicitedRAWorkerThread sraWorkerThread = new SolicitedRAWorkerThread(pkt);
    executors.schedule(sraWorkerThread, 0, TimeUnit.SECONDS);
}
 
Example #18
Source File: OpenstackTroubleshootManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void process(PacketContext context) {
    if (context.isHandled()) {
        return;
    }

    InboundPacket pkt = context.inPacket();
    Ethernet ethernet = pkt.parsed();
    if (ethernet == null || ethernet.getEtherType() == Ethernet.TYPE_ARP) {
        return;
    }

    IPv4 iPacket = (IPv4) ethernet.getPayload();
    if (iPacket.getProtocol() == IPv4.PROTOCOL_ICMP) {
        eventExecutor.execute(() -> processIcmpPacket(context, ethernet));
    }
}
 
Example #19
Source File: IcmpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processPacketIn(InboundPacket pkt) {

        boolean ipMatches = false;
        Ethernet ethernet = pkt.parsed();
        IPv4 ipv4 = (IPv4) ethernet.getPayload();
        ConnectPoint connectPoint = pkt.receivedFrom();
        IpAddress destIpAddress = IpAddress.valueOf(ipv4.getDestinationAddress());
        Interface targetInterface = interfaceService.getMatchingInterface(destIpAddress);

        if (targetInterface == null) {
            log.trace("No matching interface for {}", destIpAddress);
            return;
        }

        for (InterfaceIpAddress interfaceIpAddress: targetInterface.ipAddressesList()) {
            if (interfaceIpAddress.ipAddress().equals(destIpAddress)) {
                ipMatches = true;
                break;
            }
        }

        if (((ICMP) ipv4.getPayload()).getIcmpType() == ICMP.TYPE_ECHO_REQUEST &&
                ipMatches) {
            sendIcmpResponse(ethernet, connectPoint);
        }
    }
 
Example #20
Source File: NeighbourResolutionManager.java    From onos with Apache License 2.0 6 votes vote down vote up
private void handlePacket(PacketContext context) {
    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();

    NeighbourMessageContext msgContext =
            DefaultNeighbourMessageContext.createContext(ethPkt, pkt.receivedFrom(), actions);

    if (msgContext == null) {
        return;
    }

    if (handleMessage(msgContext)) {
        context.block();
    }

}
 
Example #21
Source File: CastorArpManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean handlePacket(PacketContext context) {

    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();

    if (ethPkt == null) {
        return false;
    }

    MessageContext msgContext = createContext(ethPkt, pkt.receivedFrom());

    if (msgContext == null) {
        return false;
    }
    switch (msgContext.type()) {
        case REPLY:
            forward(msgContext);
            updateMac(msgContext);
            handleArpForL2(msgContext);
            break;
        case REQUEST:
            forward(msgContext);
            updateMac(msgContext);
            handleArpForL2(msgContext);
            break;
        default:
            return false;
    }
    context.block();
    return true;
}
 
Example #22
Source File: DefaultVirtualPacketContext.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new packet context.
 *
 * @param time   creation time
 * @param inPkt  inbound packet
 * @param outPkt outbound packet
 * @param block  whether the context is blocked or not
 * @param networkId virtual network ID where this context is handled
 * @param dvpp  pointer to default virtual packet provider
 */

protected DefaultVirtualPacketContext(long time, InboundPacket inPkt,
                                      OutboundPacket outPkt, boolean block,
                                      NetworkId networkId,
                                      DefaultVirtualPacketProvider dvpp) {
    super(time, inPkt, outPkt, block);

    this.networkId = networkId;
    this.dvpp = dvpp;
}
 
Example #23
Source File: DefaultVirtualPacketProviderTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/** Test the physical packet context is delivered to a proper (physical)
 *  virtual network and device.
 */
@Test
public void virtualizePacket() {
    Ethernet eth = new Ethernet();
    eth.setSourceMACAddress(SRC_MAC_ADDR);
    eth.setDestinationMACAddress(DST_MAC_ADDR);
    eth.setVlanID((short) 1);
    eth.setPayload(null);

    InboundPacket pInPacket =
            new DefaultInboundPacket(CP22, eth,
                                     ByteBuffer.wrap(eth.serialize()));

    PacketContext pContext =
            new TestPacketContext(System.nanoTime(), pInPacket, null, false);

    testPacketService.sendTestPacketContext(pContext);

    PacketContext vContext = providerService.getRequestedPacketContext(0);
    InboundPacket vInPacket = vContext.inPacket();

    assertEquals("the packet should be received from VCP12",
                 VCP12, vInPacket.receivedFrom());

    assertEquals("VLAN tag should be excludede", VlanId.UNTAGGED,
                 vInPacket.parsed().getVlanID());
}
 
Example #24
Source File: OpenstackRoutingSnatHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private void populateSnatFlowRules(InboundPacket packetIn,
                                   InstancePort srcInstPort,
                                   TpPort patPort, IpAddress externalIp,
                                   ExternalPeerRouter externalPeerRouter) {
    Network osNet = osNetworkService.network(srcInstPort.networkId());
    Type netType = osNetworkService.networkType(srcInstPort.networkId());

    if (osNet == null) {
        final String error = String.format("%s network %s not found",
                ERR_PACKET_IN, srcInstPort.networkId());
        throw new IllegalStateException(error);
    }

    setStatelessSnatDownstreamRules(srcInstPort,
            osNet.getProviderSegID(),
            netType,
            externalIp,
            externalPeerRouter,
            patPort,
            packetIn);

    setStatelessSnatUpstreamRules(osNet.getProviderSegID(),
            netType,
            externalIp,
            externalPeerRouter,
            patPort,
            packetIn);
}
 
Example #25
Source File: VtnManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void process(PacketContext context) {
    InboundPacket pkt = context.inPacket();
    ConnectPoint connectPoint = pkt.receivedFrom();
    DeviceId deviceId = connectPoint.deviceId();
    Ethernet ethPkt = pkt.parsed();
    if (ethPkt == null) {
        return;
    }
    if (ethPkt.getEtherType() == Ethernet.TYPE_ARP) {
        ARP arpPacket = (ARP) ethPkt.getPayload();
        if ((arpPacket.getOpCode() == ARP.OP_REQUEST)) {
            arprequestProcess(arpPacket, deviceId);
        } else if (arpPacket.getOpCode() == ARP.OP_REPLY) {
            arpresponceProcess(arpPacket, deviceId);
        }
    } else if (ethPkt.getEtherType() == Ethernet.TYPE_IPV4) {
        if (ethPkt.getDestinationMAC().isMulticast()) {
            return;
        }
        IPv4 ip = (IPv4) ethPkt.getPayload();
        upStreamPacketProcessor(ip, deviceId);

    } else {
        return;
    }
}
 
Example #26
Source File: OpenstackSwitchingDhcpHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #27
Source File: OpenstackRoutingSnatIcmpHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #28
Source File: OpenstackSwitchingArpHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #29
Source File: SimpleFabricRouting.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void process(PacketContext context) {
    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();
    if (ethPkt == null) {
        return;
    }
    ConnectPoint srcCp = pkt.receivedFrom();
    IpAddress srcIp;
    IpAddress dstIp;
    byte ipProto = 0;  /* 0 or tcp, udp */

    switch (EthType.EtherType.lookup(ethPkt.getEtherType())) {
    case IPV4:
        IPv4 ipv4Packet = (IPv4) ethPkt.getPayload();
        srcIp = IpAddress.valueOf(ipv4Packet.getSourceAddress());
        dstIp = IpAddress.valueOf(ipv4Packet.getDestinationAddress());
        ipProto = ipv4Packet.getProtocol();
        break;
    case IPV6:
        IPv6 ipv6Packet = (IPv6) ethPkt.getPayload();
        srcIp = IpAddress.valueOf(IpAddress.Version.INET6, ipv6Packet.getSourceAddress());
        dstIp = IpAddress.valueOf(IpAddress.Version.INET6, ipv6Packet.getDestinationAddress());
        ipProto = ipv6Packet.getNextHeader();
        break;
    default:
        return;  // ignore unknow ether type packets
    }
    if (ipProto != 6 && ipProto != 17) {
        ipProto = 0;  /* handle special for TCP and UDP only */
    }

    if (!checkVirtualGatewayIpPacket(pkt, srcIp, dstIp)) {
        ipPacketReactiveProcessor(context, ethPkt, srcCp, srcIp, dstIp, ipProto);
        // TODO: add ReactiveRouting for dstIp to srcIp with discovered egressCp as srcCp
    }
}
 
Example #30
Source File: BasicInterpreterImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public InboundPacket mapInboundPacket(PiPacketOperation packetIn, DeviceId deviceId)
        throws PiInterpreterException {
    // Assuming that the packet is ethernet, which is fine since basic.p4
    // can deparse only ethernet packets.
    Ethernet ethPkt;
    try {
        ethPkt = Ethernet.deserializer().deserialize(packetIn.data().asArray(), 0,
                                                     packetIn.data().size());
    } catch (DeserializationException dex) {
        throw new PiInterpreterException(dex.getMessage());
    }

    // Returns the ingress port packet metadata.
    Optional<PiPacketMetadata> packetMetadata = packetIn.metadatas()
            .stream().filter(m -> m.id().equals(INGRESS_PORT))
            .findFirst();

    if (packetMetadata.isPresent()) {
        ImmutableByteSequence portByteSequence = packetMetadata.get().value();
        short s = portByteSequence.asReadOnlyBuffer().getShort();
        ConnectPoint receivedFrom = new ConnectPoint(deviceId, PortNumber.portNumber(s));
        ByteBuffer rawData = ByteBuffer.wrap(packetIn.data().asArray());
        return new DefaultInboundPacket(receivedFrom, ethPkt, rawData);
    } else {
        throw new PiInterpreterException(format(
                "Missing metadata '%s' in packet-in received from '%s': %s",
                INGRESS_PORT, deviceId, packetIn));
    }
}