org.onosproject.net.packet.DefaultInboundPacket Java Examples

The following examples show how to use org.onosproject.net.packet.DefaultInboundPacket. 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() {
    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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
Source File: OpenFlowPacketProvider.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void handlePacket(OpenFlowPacketContext pktCtx) {
    DeviceId id = DeviceId.deviceId(Dpid.uri(pktCtx.dpid().value()));

    DefaultInboundPacket inPkt = new DefaultInboundPacket(
            new ConnectPoint(id, PortNumber.portNumber(pktCtx.inPort())),
            pktCtx.parsed(), ByteBuffer.wrap(pktCtx.unparsed()),
            pktCtx.cookie());

    DefaultOutboundPacket outPkt = null;
    if (!pktCtx.isBuffered()) {
        outPkt = new DefaultOutboundPacket(id, null,
                ByteBuffer.wrap(pktCtx.unparsed()));
    }

    OpenFlowCorePacketContext corePktCtx =
            new OpenFlowCorePacketContext(System.currentTimeMillis(),
                    inPkt, outPkt, pktCtx.isHandled(), pktCtx);
    providerService.processPacket(corePktCtx);
}
 
Example #13
Source File: DhcpRelayManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
public TestArpRequestPacketContext(Interface fromInterface) {
    super(0, null, null, false);
    ARP arp = new ARP();
    arp.setOpCode(ARP.OP_REQUEST);

    IpAddress targetIp = fromInterface.ipAddressesList().get(0).ipAddress();
    arp.setTargetProtocolAddress(targetIp.toOctets());
    arp.setTargetHardwareAddress(MacAddress.BROADCAST.toBytes());
    arp.setSenderHardwareAddress(MacAddress.NONE.toBytes());
    arp.setSenderProtocolAddress(Ip4Address.valueOf(0).toOctets());
    arp.setHardwareAddressLength((byte) MacAddress.MAC_ADDRESS_LENGTH);
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_ARP);
    eth.setSourceMACAddress(MacAddress.NONE);
    eth.setDestinationMACAddress(MacAddress.BROADCAST);
    eth.setVlanID(fromInterface.vlan().toShort());
    eth.setPayload(arp);

    this.inPacket = new DefaultInboundPacket(fromInterface.connectPoint(), eth,
                                             ByteBuffer.wrap(eth.serialize()));
}
 
Example #14
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 #15
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 #16
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));
    }
}
 
Example #17
Source File: FabricInterpreter.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 fabric.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(FabricConstants.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",
                FabricConstants.INGRESS_PORT, deviceId, packetIn));
    }
}
 
Example #18
Source File: DhcpManagerTest.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 reply Ethernet packet
 */
private void sendPacket(Ethernet reply) {
    final ByteBuffer byteBuffer = ByteBuffer.wrap(reply.serialize());
    InboundPacket inPacket = new DefaultInboundPacket(connectPoint("1", 1),
            reply,
            byteBuffer);

    PacketContext context = new TestPacketContext(127L, inPacket, null, false);
    packetProcessor.process(context);
}
 
Example #19
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 #20
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 #21
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public InboundPacket inPacket() {

    DHCP6 dhcp6 = new DHCP6();
    dhcp6.setMsgType(DHCP6.MsgType.REQUEST.value());
    List<Dhcp6Option> options = Lists.newArrayList();

    // IA address
    Dhcp6IaAddressOption iaAddressOption = new Dhcp6IaAddressOption();
    iaAddressOption.setIp6Address(IP_ADDRESS2.getIp6Address());

    // IA NA
    Dhcp6IaNaOption iaNaOption = new Dhcp6IaNaOption();
    iaNaOption.setOptions(ImmutableList.of(iaAddressOption));
    options.add(iaNaOption);

    dhcp6.setOptions(options);

    UDP udp = new UDP();
    udp.setPayload(dhcp6);
    udp.setSourcePort(UDP.DHCP_V6_CLIENT_PORT);
    udp.setDestinationPort(UDP.DHCP_V6_SERVER_PORT);
    IPv6 ipv6 = new IPv6();
    ipv6.setPayload(udp);
    ipv6.setDestinationAddress(Ip6Address.ZERO.toOctets());
    ipv6.setSourceAddress(Ip6Address.ZERO.toOctets());
    ipv6.setNextHeader(IPv6.PROTOCOL_UDP);
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV6)
            .setVlanID(this.vlanId.toShort())
            .setSourceMACAddress(MAC2)
            .setDestinationMACAddress(DHCP6_SERVER_MAC)
            .setPayload(ipv6);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
                                                 portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
                                    ByteBuffer.wrap(eth.serialize()));
}
 
Example #22
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public InboundPacket inPacket() {
    byte[] dhcpMsgType = new byte[1];
    dhcpMsgType[0] = (byte) DHCP.MsgType.DHCPACK.getValue();

    DhcpOption dhcpOption = new DhcpOption();
    dhcpOption.setCode(DHCP.DHCPOptionCode.OptionCode_MessageType.getValue());
    dhcpOption.setData(dhcpMsgType);
    dhcpOption.setLength((byte) 1);

    DHCP dhcp = new DHCP();
    dhcp.setOptions(ImmutableList.of(dhcpOption));

    dhcp.setClientHardwareAddress(MAC.toBytes());
    dhcp.setYourIPAddress(IP_ADDRESS.getIp4Address().toInt());

    UDP udp = new UDP();
    udp.setPayload(dhcp);
    udp.setSourcePort(UDP.DHCP_SERVER_PORT);
    udp.setDestinationPort(UDP.DHCP_CLIENT_PORT);
    IPv4 ipv4 = new IPv4();
    ipv4.setPayload(udp);
    ipv4.setDestinationAddress(IP_ADDRESS.toString());
    ipv4.setSourceAddress(IP_ADDRESS3.toString());
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV4)
            .setVlanID(VLAN.toShort())
            .setSourceMACAddress(MAC3)
            .setDestinationMACAddress(MAC)
            .setPayload(ipv4);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
            portNumber(INPORT2));
    return new DefaultInboundPacket(receivedFrom, eth,
            ByteBuffer.wrap(eth.serialize()));
}
 
Example #23
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public InboundPacket inPacket() {
    byte[] dhcpMsgType = new byte[1];
    dhcpMsgType[0] = (byte) DHCP.MsgType.DHCPREQUEST.getValue();

    DhcpOption dhcpOption = new DhcpOption();
    dhcpOption.setCode(DHCP.DHCPOptionCode.OptionCode_MessageType.getValue());
    dhcpOption.setData(dhcpMsgType);
    dhcpOption.setLength((byte) 1);
    DHCP dhcp = new DHCP();
    dhcp.setOptions(Collections.singletonList(dhcpOption));
    dhcp.setClientHardwareAddress(MAC.toBytes());
    UDP udp = new UDP();
    udp.setPayload(dhcp);
    udp.setSourcePort(UDP.DHCP_CLIENT_PORT);
    udp.setDestinationPort(UDP.DHCP_SERVER_PORT);
    IPv4 ipv4 = new IPv4();
    ipv4.setPayload(udp);
    ipv4.setDestinationAddress(IP_ADDRESS3.toString());
    ipv4.setSourceAddress(IP_ADDRESS.toString());
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV4)
            .setVlanID(this.vlanId.toShort())
            .setSourceMACAddress(MAC)
            .setDestinationMACAddress(MAC3)
            .setPayload(ipv4);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
            portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
            ByteBuffer.wrap(eth.serialize()));
}
 
Example #24
Source File: NullPacketProvider.java    From onos with Apache License 2.0 5 votes vote down vote up
private void sendEvent(Device device) {
    // Make it look like things came from ports attached to hosts
    eth.setSourceMACAddress("00:00:00:10:00:0" + SRC_HOST)
            .setDestinationMACAddress("00:00:00:10:00:0" + DST_HOST);
    InboundPacket inPkt = new DefaultInboundPacket(
            new ConnectPoint(device.id(), PortNumber.portNumber(SRC_HOST)),
            eth, ByteBuffer.wrap(eth.serialize()));
    providerService.processPacket(new NullPacketContext(inPkt, null));
}
 
Example #25
Source File: OFChannelHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Parse OpenFlow message context for get Ethernet packet.
 *
 * @param message OpenFlow message
 * @return parsed Ethernet packet
 */
private Ethernet parsePacketInMessage(OFMessage message) {
    OpenFlowPacketContext pktCtx = DefaultOpenFlowPacketContext
            .packetContextFromPacketIn(sw, (OFPacketIn) message);
    DeviceId id = DeviceId.deviceId(Dpid.uri(pktCtx.dpid().value()));
    DefaultInboundPacket inPkt = new DefaultInboundPacket(
            new ConnectPoint(id, PortNumber.portNumber(pktCtx.inPort())),
            pktCtx.parsed(), ByteBuffer.wrap(pktCtx.unparsed()),
            pktCtx.cookie());
    return inPkt.parsed();
}
 
Example #26
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 #27
Source File: PipelineInterpreterImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public InboundPacket mapInboundPacket(PiPacketOperation packetIn, DeviceId deviceId)
        throws PiInterpreterException {
    // We assume that the packet is ethernet, which is fine since mytunnel.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(metadata -> metadata.id().toString().equals(INGRESS_PORT))
            .findFirst();

    if (packetMetadata.isPresent()) {
        short s = packetMetadata.get().value().asReadOnlyBuffer().getShort();
        ConnectPoint receivedFrom = new ConnectPoint(
                deviceId, PortNumber.portNumber(s));
        return new DefaultInboundPacket(
                receivedFrom, ethPkt, packetIn.data().asReadOnlyBuffer());
    } else {
        throw new PiInterpreterException(format(
                "Missing metadata '%s' in packet-in received from '%s': %s",
                INGRESS_PORT, deviceId, packetIn));
    }
}
 
Example #28
Source File: InterpreterImpl.java    From ngsdn-tutorial with Apache License 2.0 4 votes vote down vote up
/**
 * Returns an ONS InboundPacket equivalent to the given pipeconf-specific
 * packet-in operation.
 *
 * @param packetIn packet operation
 * @param deviceId ID of the device that originated the packet-in
 * @return inbound packet
 * @throws PiInterpreterException if the packet operation cannot be mapped
 *                                to an inbound packet
 */
@Override
public InboundPacket mapInboundPacket(PiPacketOperation packetIn, DeviceId deviceId)
        throws PiInterpreterException {

    // Find the ingress_port metadata.
    // *** TODO EXERCISE 3: modify metadata names to match P4Info
    // ---- START SOLUTION ----
    final String inportMetadataName = "<ADD HERE METADATA NAME FOR THE INGRESS PORT>";
    // ---- END SOLUTION ----
    Optional<PiPacketMetadata> inportMetadata = packetIn.metadatas()
            .stream()
            .filter(meta -> meta.id().id().equals(inportMetadataName))
            .findFirst();

    if (!inportMetadata.isPresent()) {
        throw new PiInterpreterException(format(
                "Missing metadata '%s' in packet-in received from '%s': %s",
                inportMetadataName, deviceId, packetIn));
    }

    // Build ONOS InboundPacket instance with the given ingress port.

    // 1. Parse packet-in object into Ethernet packet instance.
    final byte[] payloadBytes = packetIn.data().asArray();
    final ByteBuffer rawData = ByteBuffer.wrap(payloadBytes);
    final Ethernet ethPkt;
    try {
        ethPkt = Ethernet.deserializer().deserialize(
                payloadBytes, 0, packetIn.data().size());
    } catch (DeserializationException dex) {
        throw new PiInterpreterException(dex.getMessage());
    }

    // 2. Get ingress port
    final ImmutableByteSequence portBytes = inportMetadata.get().value();
    final short portNum = portBytes.asReadOnlyBuffer().getShort();
    final ConnectPoint receivedFrom = new ConnectPoint(
            deviceId, PortNumber.portNumber(portNum));

    return new DefaultInboundPacket(receivedFrom, ethPkt, rawData);
}
 
Example #29
Source File: DhcpRelayManagerTest.java    From onos with Apache License 2.0 4 votes vote down vote up
public TestDhcp6ReplyPacketContext(byte msgType, ConnectPoint clientCp, MacAddress clientMac,
                                VlanId clientVlan, Ip6Address clientGwAddr,
                                int relayLevel, boolean overWriteFlag, VlanId overWriteVlan) {
    super(0, null, null, false);


    DHCP6 dhcp6Payload = new DHCP6();
    buildDhcp6Packet(dhcp6Payload, msgType,
            IP_FOR_CLIENT_V6,
            PREFIX_FOR_CLIENT_V6);
    byte[] interfaceId = null;
    if (relayLevel > 0) {
        interfaceId = buildInterfaceId(OUTER_RELAY_MAC,
                                       overWriteFlag ? overWriteVlan.toShort() : OUTER_RELAY_VLAN.toShort(),
                                        OUTER_RELAY_CP);
    } else {
        interfaceId = buildInterfaceId(clientMac, clientVlan.toShort(), clientCp);
    }
    DHCP6 dhcp6 = new DHCP6();
    buildRelayMsg(dhcp6, DHCP6.MsgType.RELAY_REPL.value(),
                  INTERFACE_IP_V6.ipAddress().getIp6Address(),
                  CLIENT_LL_IP_V6,
                  (byte) 0, interfaceId,
                  dhcp6Payload);

    DHCP6 dhcp6Parent = null;
    DHCP6 dhcp6Child = dhcp6;
    for (int i = 0; i < relayLevel; i++) {   // relayLevel 0 : no relay
        dhcp6Parent = new DHCP6();

        buildRelayMsg(dhcp6Parent, DHCP6.MsgType.RELAY_REPL.value(),
                INTERFACE_IP_V6.ipAddress().getIp6Address(),
                OUTER_RELAY_IP_V6,
                (byte) relayLevel, interfaceId,
                dhcp6Child);

        dhcp6Child = dhcp6Parent;
    }
    if (dhcp6Parent != null) {
        dhcp6 = dhcp6Parent;
    }


    UDP udp = new UDP();
    udp.setPayload(dhcp6);
    udp.setSourcePort(UDP.DHCP_V6_SERVER_PORT);
    udp.setDestinationPort(UDP.DHCP_V6_CLIENT_PORT);
    IPv6 ipv6 = new IPv6();
    ipv6.setPayload(udp);
    ipv6.setNextHeader(IPv6.PROTOCOL_UDP);
    ipv6.setDestinationAddress(IP_FOR_CLIENT_V6.toOctets());
    ipv6.setSourceAddress(SERVER_IP_V6.toOctets());
    Ethernet eth = new Ethernet();
    if (relayLevel > 0) {
        eth.setEtherType(Ethernet.TYPE_IPV6)
                .setVlanID(SERVER_VLAN.toShort())
                .setSourceMACAddress(SERVER_MAC)
                .setDestinationMACAddress(OUTER_RELAY_MAC)
                .setPayload(ipv6);
    } else {
        eth.setEtherType(Ethernet.TYPE_IPV6)
                .setVlanID(SERVER_VLAN.toShort())
                .setSourceMACAddress(SERVER_MAC)
                .setDestinationMACAddress(CLIENT_MAC)
                .setPayload(ipv6);
    }

    this.inPacket = new DefaultInboundPacket(SERVER_CONNECT_POINT, eth,
                                             ByteBuffer.wrap(eth.serialize()));

}
 
Example #30
Source File: DhcpRelayManagerTest.java    From onos with Apache License 2.0 4 votes vote down vote up
public TestDhcp6RequestPacketContext(byte msgType, MacAddress clientMac, VlanId vlanId,
                                    ConnectPoint clientCp,
                                    Ip6Address clientGwAddr,
                                    int relayLevel) {
    super(0, null, null, false);

    DHCP6 dhcp6 = new DHCP6();
    if (relayLevel > 0) {
        DHCP6 dhcp6Payload = new DHCP6();
        buildDhcp6Packet(dhcp6Payload, msgType,
                         IP_FOR_CLIENT_V6,
                msgType == DHCP6.MsgType.REQUEST.value() ? PREFIX_FOR_ZERO : PREFIX_FOR_CLIENT_V6);
        DHCP6 dhcp6Parent = null;
        DHCP6 dhcp6Child = dhcp6Payload;
        for (int i = 0; i < relayLevel; i++) {
            dhcp6Parent = new DHCP6();
            byte[] interfaceId = buildInterfaceId(clientMac, vlanId.toShort(), clientCp);
            buildRelayMsg(dhcp6Parent, DHCP6.MsgType.RELAY_FORW.value(),
                    INTERFACE_IP_V6.ipAddress().getIp6Address(),
                    OUTER_RELAY_IP_V6,
                    (byte) (relayLevel - 1), interfaceId,
                    dhcp6Child);
            dhcp6Child = dhcp6Parent;
        }
        if (dhcp6Parent != null) {
            dhcp6 = dhcp6Parent;
        }
    } else {
        buildDhcp6Packet(dhcp6, msgType,
                                IP_FOR_CLIENT_V6,
                msgType == DHCP6.MsgType.REQUEST.value() ? PREFIX_FOR_ZERO : PREFIX_FOR_CLIENT_V6);
    }

    UDP udp = new UDP();
    udp.setPayload(dhcp6);
    if (relayLevel > 0) {
        udp.setSourcePort(UDP.DHCP_V6_SERVER_PORT);
    } else {
        udp.setSourcePort(UDP.DHCP_V6_CLIENT_PORT);
    }
    udp.setDestinationPort(UDP.DHCP_V6_SERVER_PORT);

    IPv6 ipv6 = new IPv6();
    ipv6.setPayload(udp);
    ipv6.setNextHeader(IPv6.PROTOCOL_UDP);
    ipv6.setDestinationAddress(SERVER_IP_V6_MCAST.toOctets());
    ipv6.setSourceAddress(clientGwAddr.toOctets());

    Ethernet eth = new Ethernet();
    if (relayLevel > 0) {
        eth.setEtherType(Ethernet.TYPE_IPV6)
                .setVlanID(OUTER_RELAY_VLAN.toShort())
                .setSourceMACAddress(OUTER_RELAY_MAC)
                .setDestinationMACAddress(MacAddress.valueOf("33:33:00:01:00:02"))
                .setPayload(ipv6);
    } else {
        eth.setEtherType(Ethernet.TYPE_IPV6)
                .setVlanID(vlanId.toShort())
                .setSourceMACAddress(clientMac)
                .setDestinationMACAddress(MacAddress.valueOf("33:33:00:01:00:02"))
                .setPayload(ipv6);
    }
    this.inPacket = new DefaultInboundPacket(clientCp, eth,
                                             ByteBuffer.wrap(eth.serialize()));
}