org.onlab.packet.DeserializationException Java Examples
The following examples show how to use
org.onlab.packet.DeserializationException.
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: RouterAdvertisementTest.java From onos with Apache License 2.0 | 6 votes |
/** * Tests deserialize and getters. */ @Test public void testDeserialize() throws DeserializationException { RouterAdvertisement ra = deserializer.deserialize(bytePacket, 0, bytePacket.length); assertThat(ra.getCurrentHopLimit(), is((byte) 3)); assertThat(ra.getMFlag(), is((byte) 1)); assertThat(ra.getOFlag(), is((byte) 1)); assertThat(ra.getRouterLifetime(), is((short) 0x258)); assertThat(ra.getReachableTime(), is(0x3e8)); assertThat(ra.getRetransmitTimer(), is(0x1f4)); // Check the option(s) assertThat(ra.getOptions().size(), is(1)); NeighborDiscoveryOptions.Option option = ra.getOptions().get(0); assertThat(option.type(), is(NeighborDiscoveryOptions.TYPE_TARGET_LL_ADDRESS)); assertArrayEquals(option.data(), MAC_ADDRESS.toBytes()); }
Example #2
Source File: Dhcp6ClientIdOption.java From onos with Apache License 2.0 | 6 votes |
public static Deserializer<Dhcp6Option> deserializer() { return (data, offset, length) -> { Dhcp6Option dhcp6Option = Dhcp6Option.deserializer().deserialize(data, offset, length); Dhcp6ClientIdOption clientIdentifier = new Dhcp6ClientIdOption(); if (dhcp6Option.getLength() < DEFAULT_LEN) { throw new DeserializationException("Invalid length of Client Id option"); } Dhcp6Duid duid = Dhcp6Duid.deserializer().deserialize(dhcp6Option.getData(), 0, dhcp6Option.getLength()); clientIdentifier.setPayload(duid); return clientIdentifier; }; }
Example #3
Source File: Dhcp6Option.java From onos with Apache License 2.0 | 6 votes |
/** * Gets deserializer of DHCPv6 option. * * @return the deserializer of DHCPv6 option */ public static Deserializer<Dhcp6Option> deserializer() { return (data, offset, len) -> { Dhcp6Option dhcp6Option = new Dhcp6Option(); if (len < DEFAULT_LEN) { throw new DeserializationException("DHCPv6 option code length" + "should be at least 4 bytes"); } ByteBuffer bb = ByteBuffer.wrap(data, offset, len); dhcp6Option.code = bb.getShort(); dhcp6Option.length = bb.getShort(); int optionLen = UNSIGNED_SHORT_MASK & dhcp6Option.length; byte[] optData = new byte[optionLen]; bb.get(optData); dhcp6Option.setData(optData); return dhcp6Option; }; }
Example #4
Source File: RouteAttributeDst.java From onos with Apache License 2.0 | 6 votes |
/** * Returns a decoder for a destination address route attribute. * * @return destination address route attribute decoder */ public static RouteAttributeDecoder<RouteAttributeDst> decoder() { return (int length, int type, byte[] value) -> { IpAddress dstAddress; if (value.length == Ip4Address.BYTE_LENGTH) { dstAddress = IpAddress.valueOf(IpAddress.Version.INET, value); } else if (value.length == Ip6Address.BYTE_LENGTH) { dstAddress = IpAddress.valueOf(IpAddress.Version.INET6, value); } else { throw new DeserializationException("Invalid address length"); } return new RouteAttributeDst(length, type, dstAddress); }; }
Example #5
Source File: Dhcp6CLTOption.java From onos with Apache License 2.0 | 6 votes |
/** * Gets deserializer. * * @return the deserializer */ public static Deserializer<Dhcp6Option> deserializer() { return (data, offset, length) -> { Dhcp6Option dhcp6Option = Dhcp6Option.deserializer().deserialize(data, offset, length); if (dhcp6Option.getLength() < DEFAULT_LEN) { throw new DeserializationException("Invalid CLT option data"); } Dhcp6CLTOption cltOption = new Dhcp6CLTOption(dhcp6Option); byte[] optionData = cltOption.getData(); ByteBuffer bb = ByteBuffer.wrap(optionData); cltOption.clt = bb.getInt(); return cltOption; }; }
Example #6
Source File: PIMAddrUnicast.java From onos with Apache License 2.0 | 6 votes |
public PIMAddrUnicast deserialize(ByteBuffer bb) throws DeserializationException { // Assume IPv4 for check length until we read the encoded family. checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_UNICAST_IPV4_BYTE_LENGTH); this.family = bb.get(); // If we have IPv6 we need to ensure we have adequate buffer space. if (this.family != PIM.ADDRESS_FAMILY_IP4 && this.family != PIM.ADDRESS_FAMILY_IP6) { throw new DeserializationException("Invalid address family: " + this.family); } else if (this.family == PIM.ADDRESS_FAMILY_IP6) { // Subtract -1 from ENC_UNICAST_IPv6 BYTE_LENGTH because we read one byte for family previously. checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_UNICAST_IPV6_BYTE_LENGTH - 1); } this.encType = bb.get(); if (this.family == PIM.ADDRESS_FAMILY_IP4) { this.addr = IpAddress.valueOf(bb.getInt()); } else if (this.family == PIM.ADDRESS_FAMILY_IP6) { this.addr = Ip6Address.valueOf(bb.array(), 2); } return this; }
Example #7
Source File: RouteAttribute.java From onos with Apache License 2.0 | 6 votes |
/** * Decodes a route attribute from an input buffer. * * @param buffer input buffer * @param start starting position the route attribute message * @param length length of the message * @return route attribute message * @throws DeserializationException if a route attribute could not be * decoded from the input buffer */ public static RouteAttribute decode(byte[] buffer, int start, int length) throws DeserializationException { checkInput(buffer, start, length, ROUTE_ATTRIBUTE_HEADER_LENGTH); ByteBuffer bb = ByteBuffer.wrap(buffer, start, length); int tlvLength = Short.reverseBytes(bb.getShort()); int type = Short.reverseBytes(bb.getShort()); if (bb.remaining() < tlvLength - ROUTE_ATTRIBUTE_HEADER_LENGTH) { throw new DeserializationException( "Incorrect buffer size when decoding route attribute"); } byte[] value = new byte[tlvLength - ROUTE_ATTRIBUTE_HEADER_LENGTH]; bb.get(value); RouteAttributeDecoder<?> decoder = TYPE_DECODER_MAP.get(type); if (decoder == null) { throw new DeserializationException( "No decoder found for route attribute type " + type); } return decoder.decodeAttribute(tlvLength, type, value); }
Example #8
Source File: NeighborAdvertisementTest.java From onos with Apache License 2.0 | 6 votes |
/** * Tests deserialize and getters. */ @Test public void testDeserialize() throws DeserializationException { NeighborAdvertisement na = deserializer.deserialize(bytePacket, 0, bytePacket.length); assertThat(na.getRouterFlag(), is((byte) 1)); assertThat(na.getSolicitedFlag(), is((byte) 1)); assertThat(na.getOverrideFlag(), is((byte) 1)); assertArrayEquals(na.getTargetAddress(), TARGET_ADDRESS); // Check the option(s) assertThat(na.getOptions().size(), is(1)); NeighborDiscoveryOptions.Option option = na.getOptions().get(0); assertThat(option.type(), is(NeighborDiscoveryOptions.TYPE_TARGET_LL_ADDRESS)); assertArrayEquals(option.data(), MAC_ADDRESS.toBytes()); }
Example #9
Source File: RouteAttributeGateway.java From onos with Apache License 2.0 | 6 votes |
/** * Returns a decoder for a gateway route attribute. * * @return gateway route attribute decoder */ public static RouteAttributeDecoder<RouteAttributeGateway> decoder() { return (int length, int type, byte[] value) -> { IpAddress gateway; if (value.length == Ip4Address.BYTE_LENGTH) { gateway = IpAddress.valueOf(IpAddress.Version.INET, value); } else if (value.length == Ip6Address.BYTE_LENGTH) { gateway = IpAddress.valueOf(IpAddress.Version.INET6, value); } else { throw new DeserializationException("Invalid address length"); } return new RouteAttributeGateway(length, type, gateway); }; }
Example #10
Source File: DhcpRelayManagerTest.java From onos with Apache License 2.0 | 6 votes |
@Test public void testWithRelayAgentConfig() throws DeserializationException { manager.v4Handler .setDefaultDhcpServerConfigs(ImmutableList.of(new MockDhcpServerConfig(RELAY_AGENT_IP))); manager.v4Handler .setIndirectDhcpServerConfigs(ImmutableList.of(new MockDhcpServerConfig(RELAY_AGENT_IP))); packetService.processPacket(new TestDhcpRequestPacketContext(CLIENT2_MAC, CLIENT2_VLAN, CLIENT2_CP, INTERFACE_IP.ipAddress().getIp4Address(), true)); assertAfter(PKT_PROCESSING_MS, () -> assertNotNull(packetService.emittedPacket)); OutboundPacket outPacket = packetService.emittedPacket; byte[] outData = outPacket.data().array(); Ethernet eth = Ethernet.deserializer().deserialize(outData, 0, outData.length); IPv4 ip = (IPv4) eth.getPayload(); UDP udp = (UDP) ip.getPayload(); DHCP dhcp = (DHCP) udp.getPayload(); assertAfter(PKT_PROCESSING_MS, () -> assertEquals(RELAY_AGENT_IP.toInt(), dhcp.getGatewayIPAddress())); }
Example #11
Source File: OpenFlowCorePacketContext.java From onos with Apache License 2.0 | 6 votes |
@Override public void send() { if (!this.block()) { if (outPacket() == null) { sendPacket(null); } else { try { Ethernet eth = Ethernet.deserializer() .deserialize(outPacket().data().array(), 0, outPacket().data().array().length); sendPacket(eth); } catch (DeserializationException e) { log.warn("Unable to deserialize packet"); } } } }
Example #12
Source File: PIMAddrGroup.java From onos with Apache License 2.0 | 5 votes |
/** * Deserialze from a ByteBuffer. * * @param bb the ByteBuffer * @return an encoded PIM group address * @throws DeserializationException if unable to deserialize the packet data */ public PIMAddrGroup deserialize(ByteBuffer bb) throws DeserializationException { /* * We need to verify that we have enough buffer space. First we'll assume that * we are decoding an IPv4 address. After we read the first by (address family), * we'll determine if we actually need more buffer space for an IPv6 address. */ checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_GROUP_IPV4_BYTE_LENGTH); this.family = bb.get(); if (family != PIM.ADDRESS_FAMILY_IP4 && family != PIM.ADDRESS_FAMILY_IP6) { throw new DeserializationException("Illegal IP version number: " + family + "\n"); } else if (family == PIM.ADDRESS_FAMILY_IP6) { // Check for one less by since we have already read the first byte of the packet. checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_GROUP_IPV6_BYTE_LENGTH - 1); } this.encType = bb.get(); this.reserved = bb.get(); if ((this.reserved & 0x80) != 0) { this.bBit = true; } if ((this.reserved & 0x01) != 0) { this.zBit = true; } // Remove the z and b bits from reserved this.reserved |= 0x7d; this.masklen = bb.get(); if (this.family == PIM.ADDRESS_FAMILY_IP4) { this.addr = IpAddress.valueOf(bb.getInt()); } else if (this.family == PIM.ADDRESS_FAMILY_IP6) { this.addr = Ip6Address.valueOf(bb.array(), 2); } return this; }
Example #13
Source File: NeighborDiscoveryOptions.java From onos with Apache License 2.0 | 5 votes |
public static Deserializer<NeighborDiscoveryOptions> deserializer() { return (data, offset, length) -> { checkInput(data, offset, length, INITIAL_HEADER_REQUIRED); final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); NeighborDiscoveryOptions ndo = new NeighborDiscoveryOptions(); ndo.options.clear(); // // Deserialize all options // while (bb.hasRemaining()) { byte type = bb.get(); if (!bb.hasRemaining()) { throw new DeserializationException(BUFFER_UNDERFLOW_ERROR); } byte lengthField = bb.get(); int dataLength = lengthField * 8; // The data length field is in // unit of 8 octets // Exclude the type and length fields if (dataLength < 2) { break; } dataLength -= 2; if (bb.remaining() < dataLength) { throw new DeserializationException(BUFFER_UNDERFLOW_ERROR); } byte[] optionData = new byte[dataLength]; bb.get(optionData, 0, optionData.length); ndo.addOption(type, optionData); } return ndo; }; }
Example #14
Source File: Netlink.java From onos with Apache License 2.0 | 5 votes |
/** * Decodes a netlink header from an input buffer. * * @param buffer input buffer * @param start starting position the netlink header * @param length length of the message * @return netlink header * @throws DeserializationException if a netlink header could not be * decoded from the input buffer */ public static Netlink decode(byte[] buffer, int start, int length) throws DeserializationException { checkInput(buffer, start, length, NETLINK_HEADER_LENGTH); ByteBuffer bb = ByteBuffer.wrap(buffer, start, length); long messageLength = Integer.reverseBytes(bb.getInt()); int type = Short.reverseBytes(bb.getShort()); int flags = Short.reverseBytes(bb.getShort()); long sequence = Integer.reverseBytes(bb.getInt()); long processPortId = Integer.reverseBytes(bb.getInt()); NetlinkMessageType messageType = NetlinkMessageType.get(type); if (messageType == null) { throw new DeserializationException( "Unsupported Netlink message type: " + type); } // Netlink messages from Quagga's FPM protocol are always in the // netlink route family (family 0). RtNetlink rtNetlink = RtNetlink.decode(buffer, bb.position(), bb.limit() - bb.position()); return new Netlink(messageLength, messageType, flags, sequence, processPortId, rtNetlink); }
Example #15
Source File: FpmHeader.java From onos with Apache License 2.0 | 5 votes |
/** * Decodes an FPM header from an input buffer. * * @param buffer input buffer * @param start starting position the FPM header * @param length length of the message * @return FPM header * @throws DeserializationException if an FPM header could not be decoded * from the input buffer */ public static FpmHeader decode(byte[] buffer, int start, int length) throws DeserializationException { checkInput(buffer, start, length, FPM_HEADER_LENGTH); ByteBuffer bb = ByteBuffer.wrap(buffer, start, length); short version = bb.get(); if (!SUPPORTED_VERSIONS.contains(version)) { throw new DeserializationException(VERSION_NOT_SUPPORTED + version); } short type = bb.get(); int messageLength = bb.getShort(); if (type == FPM_TYPE_KEEPALIVE) { return new FpmHeader(version, type, messageLength, null); } if (type != FPM_TYPE_NETLINK) { throw new DeserializationException(TYPE_NOT_SUPPORTED + type); } Netlink netlink = Netlink.decode(buffer, bb.position(), bb.limit() - bb.position()); return new FpmHeader(version, type, messageLength, netlink); }
Example #16
Source File: RouteAttributeOif.java From onos with Apache License 2.0 | 5 votes |
/** * Returns a decoder for a output interface route attribute. * * @return output interface route attribute decoder */ public static RouteAttributeDecoder<RouteAttributeOif> decoder() { return (int length, int type, byte[] value) -> { if (value.length != VALUE_LENGTH) { throw new DeserializationException("Wrong value length"); } long outputInterface = Integer.reverseBytes(ByteBuffer.wrap(value).getInt()); return new RouteAttributeOif(length, type, outputInterface); }; }
Example #17
Source File: RtNetlink.java From onos with Apache License 2.0 | 5 votes |
/** * Decodes an rtnetlink message from an input buffer. * * @param buffer input buffer * @param start starting position the rtnetlink message * @param length length of the message * @return rtnetlink message * @throws DeserializationException if an rtnetlink message could not be * decoded from the input buffer */ public static RtNetlink decode(byte[] buffer, int start, int length) throws DeserializationException { checkInput(buffer, start, length, RT_NETLINK_LENGTH); ByteBuffer bb = ByteBuffer.wrap(buffer, start, length); short addressFamily = (short) (bb.get() & MASK); int dstLength = bb.get() & MASK; int srcLength = bb.get() & MASK; short tos = (short) (bb.get() & MASK); short table = (short) (bb.get() & MASK); short protocol = (short) (bb.get() & MASK); short scope = (short) (bb.get() & MASK); short type = (short) (bb.get() & MASK); long flags = Integer.reverseBytes(bb.getInt()); List<RouteAttribute> attributes = new ArrayList<>(); RtProtocol rtProtocol = RtProtocol.get(protocol); while (bb.hasRemaining()) { RouteAttribute attribute = RouteAttribute.decode(buffer, bb.position(), bb.limit() - bb.position()); attributes.add(attribute); bb.position(bb.position() + attribute.length()); } return new RtNetlink( addressFamily, dstLength, srcLength, tos, table, rtProtocol, scope, type, flags, attributes); }
Example #18
Source File: PIMHelloOption.java From onos with Apache License 2.0 | 5 votes |
public static PIMHelloOption deserialize(ByteBuffer bb) throws DeserializationException { checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), MINIMUM_OPTION_LEN_BYTES); PIMHelloOption opt = new PIMHelloOption(); opt.setOptType(bb.getShort()); opt.setOptLength(bb.getShort()); checkBufferLength(bb.limit(), bb.position(), opt.getOptLength()); opt.setValue(bb); return opt; }
Example #19
Source File: BasicInterpreterImpl.java From onos with Apache License 2.0 | 5 votes |
@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 #20
Source File: FabricInterpreter.java From onos with Apache License 2.0 | 5 votes |
@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 #21
Source File: NeighborSolicitationTest.java From onos with Apache License 2.0 | 5 votes |
/** * Tests deserialize and getters. */ @Test public void testDeserialize() throws DeserializationException { NeighborSolicitation ns = deserializer.deserialize(bytePacket, 0, bytePacket.length); assertArrayEquals(ns.getTargetAddress(), TARGET_ADDRESS); // Check the option(s) assertThat(ns.getOptions().size(), is(1)); NeighborDiscoveryOptions.Option option = ns.getOptions().get(0); assertThat(option.type(), is(NeighborDiscoveryOptions.TYPE_TARGET_LL_ADDRESS)); assertArrayEquals(option.data(), MAC_ADDRESS.toBytes()); }
Example #22
Source File: Dhcp6IaTaOption.java From onos with Apache License 2.0 | 5 votes |
/** * Gets deserializer. * * @return the deserializer */ public static Deserializer<Dhcp6Option> deserializer() { return (data, offset, length) -> { Dhcp6Option dhcp6Option = Dhcp6Option.deserializer().deserialize(data, offset, length); if (dhcp6Option.getLength() < DEFAULT_LEN) { throw new DeserializationException("Invalid IA NA option data"); } Dhcp6IaTaOption iaTaOption = new Dhcp6IaTaOption(dhcp6Option); byte[] optionData = iaTaOption.getData(); ByteBuffer bb = ByteBuffer.wrap(optionData); iaTaOption.iaId = bb.getInt(); iaTaOption.options = Lists.newArrayList(); while (bb.remaining() >= Dhcp6Option.DEFAULT_LEN) { Dhcp6Option option; ByteBuffer optByteBuffer = ByteBuffer.wrap(optionData, bb.position(), optionData.length - bb.position()); short code = optByteBuffer.getShort(); short len = optByteBuffer.getShort(); int optLen = UNSIGNED_SHORT_MASK & len; byte[] subOptData = new byte[Dhcp6Option.DEFAULT_LEN + optLen]; bb.get(subOptData); // TODO: put more sub-options? if (code == DHCP6.OptionCode.IAADDR.value()) { option = Dhcp6IaAddressOption.deserializer() .deserialize(subOptData, 0, subOptData.length); } else { option = Dhcp6Option.deserializer() .deserialize(subOptData, 0, subOptData.length); } iaTaOption.options.add(option); } return iaTaOption; }; }
Example #23
Source File: RedirectTest.java From onos with Apache License 2.0 | 5 votes |
/** * Tests deserialize and getters. */ @Test public void testDeserialize() throws DeserializationException { Redirect rd = deserializer.deserialize(bytePacket, 0, bytePacket.length); assertArrayEquals(rd.getTargetAddress(), TARGET_ADDRESS); assertArrayEquals(rd.getDestinationAddress(), DESTINATION_ADDRESS); // Check the option(s) assertThat(rd.getOptions().size(), is(1)); NeighborDiscoveryOptions.Option option = rd.getOptions().get(0); assertThat(option.type(), is(NeighborDiscoveryOptions.TYPE_TARGET_LL_ADDRESS)); assertArrayEquals(option.data(), MAC_ADDRESS.toBytes()); }
Example #24
Source File: EncapSecurityPayloadTest.java From onos with Apache License 2.0 | 5 votes |
/** * Tests deserialize and getters. */ @Test public void testDeserialize() throws DeserializationException { EncapSecurityPayload esp = deserializer.deserialize(bytePacket, 0, bytePacket.length); assertThat(esp.getSecurityParamIndex(), is(0x13572468)); assertThat(esp.getSequence(), is(0xffff00)); }
Example #25
Source File: RoutingTest.java From onos with Apache License 2.0 | 5 votes |
/** * Tests deserialize and getters. */ @Test public void testDeserialize() throws DeserializationException { Routing routing = deserializer.deserialize(bytePacket, 0, bytePacket.length); assertThat(routing.getNextHeader(), is((byte) 0x11)); assertThat(routing.getHeaderExtLength(), is((byte) 0x02)); assertThat(routing.getRoutingType(), is((byte) 0x00)); assertThat(routing.getSegmentsLeft(), is((byte) 0x03)); assertArrayEquals(routing.getRoutingData(), routingData); }
Example #26
Source File: FragmentTest.java From onos with Apache License 2.0 | 5 votes |
/** * Tests deserialize and getters. */ @Test public void testDeserialize() throws DeserializationException { Fragment frag = deserializer.deserialize(bytePacket, 0, bytePacket.length); assertThat(frag.getNextHeader(), is((byte) 0x11)); assertThat(frag.getFragmentOffset(), is((short) 0x1f)); assertThat(frag.getMoreFragment(), is((byte) 1)); assertThat(frag.getIdentification(), is(0x1357)); }
Example #27
Source File: DefaultLispReferralTest.java From onos with Apache License 2.0 | 5 votes |
@Test public void testSerialization() throws LispReaderException, LispWriterException, LispParseError, DeserializationException { ByteBuf byteBuf = Unpooled.buffer(); ReferralWriter writer = new ReferralWriter(); writer.writeTo(byteBuf, referral1); ReferralReader reader = new ReferralReader(); LispReferral deserialized = reader.readFrom(byteBuf); new EqualsTester() .addEqualityGroup(referral1, deserialized).testEquals(); }
Example #28
Source File: PipelineInterpreterImpl.java From onos with Apache License 2.0 | 5 votes |
@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 #29
Source File: MockPacketService.java From onos with Apache License 2.0 | 5 votes |
@Override public void emit(OutboundPacket packet) { try { Ethernet ethernetPacket = Ethernet.deserializer().deserialize(packet.data().array(), packet.data().arrayOffset(), packet.data().array().length); outBoundPackets.put(ethernetPacket.getDestinationMAC(), Pair.of(packet, ethernetPacket)); } catch (DeserializationException e) { } }
Example #30
Source File: DefaultLispMapReferral.java From onos with Apache License 2.0 | 5 votes |
@Override public LispMapReferral readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException, DeserializationException { if (byteBuf.readerIndex() != 0) { return null; } // let's skip the reserved field byteBuf.skipBytes(RESERVED_SKIP_LENGTH); // record count -> 8 bits byte recordCount = (byte) byteBuf.readUnsignedByte(); // nonce -> 64 bits long nonce = byteBuf.readLong(); List<LispReferralRecord> referralRecords = Lists.newArrayList(); for (int i = 0; i < recordCount; i++) { referralRecords.add(new ReferralRecordReader().readFrom(byteBuf)); } return new DefaultMapReferralBuilder() .withNonce(nonce) .withReferralRecords(referralRecords) .build(); }