use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class Dhcp6Test method serializeSolicit.
/**
* Test serialize solicit message.
*
* @throws Exception exception while serialize the DHCPv6 payload
*/
@Test
public void serializeSolicit() throws Exception {
DHCP6 dhcp6 = new DHCP6();
dhcp6.setMsgType(DHCP6.MsgType.SOLICIT.value());
dhcp6.setTransactionId(XID_1);
List<Dhcp6Option> options = Lists.newArrayList();
// Client ID
Dhcp6Duid duid = new Dhcp6Duid();
duid.setDuidType(Dhcp6Duid.DuidType.DUID_LLT);
duid.setHardwareType((short) 1);
duid.setDuidTime(CLIENT_DUID_TIME);
duid.setLinkLayerAddress(CLIENT_MAC.toBytes());
Dhcp6ClientIdOption clientIdOption = new Dhcp6ClientIdOption();
clientIdOption.setDuid(duid);
options.add(clientIdOption);
// Option request
Dhcp6Option option = new Dhcp6Option();
option.setCode(DHCP6.OptionCode.ORO.value());
option.setLength((short) 8);
option.setData(new byte[] { 0, 23, 0, 24, 0, 39, 0, 31 });
options.add(option);
// Elapsed Time
option = new Dhcp6Option();
option.setCode(DHCP6.OptionCode.ELAPSED_TIME.value());
option.setLength((short) 2);
option.setData(new byte[] { 0, 0 });
options.add(option);
// IA NA
Dhcp6IaNaOption iaNaOption = new Dhcp6IaNaOption();
iaNaOption.setIaId(IA_ID);
iaNaOption.setT1(T1_CLIENT);
iaNaOption.setT2(T2_CLIENT);
Dhcp6IaAddressOption iaAddressOption = new Dhcp6IaAddressOption();
iaAddressOption.setIp6Address(IA_ADDRESS);
iaAddressOption.setPreferredLifetime(PREFFERRED_LT_REQ);
iaAddressOption.setValidLifetime(VALID_LT_REQ);
iaNaOption.setOptions(ImmutableList.of(iaAddressOption));
options.add(iaNaOption);
dhcp6.setOptions(options);
Dhcp6RelayOption relayOption = new Dhcp6RelayOption();
relayOption.setPayload(dhcp6);
UDP udp = new UDP();
udp.setSourcePort(UDP.DHCP_V6_CLIENT_PORT);
udp.setDestinationPort(UDP.DHCP_V6_SERVER_PORT);
udp.setPayload(dhcp6);
udp.setChecksum((short) 0xffaf);
IPv6 ipv6 = new IPv6();
ipv6.setHopLimit((byte) 1);
ipv6.setSourceAddress(CLIENT_LL.toOctets());
ipv6.setDestinationAddress(DHCP6_BRC.toOctets());
ipv6.setNextHeader(IPv6.PROTOCOL_UDP);
ipv6.setTrafficClass((byte) 0);
ipv6.setFlowLabel(0x000322ad);
ipv6.setPayload(udp);
Ethernet eth = new Ethernet();
eth.setDestinationMACAddress(IPV6_MCAST);
eth.setSourceMACAddress(CLIENT_MAC);
eth.setEtherType(Ethernet.TYPE_IPV6);
eth.setPayload(ipv6);
assertArrayEquals(Resources.toByteArray(Dhcp6RelayTest.class.getResource(SOLICIT)), eth.serialize());
}
use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class Dhcp6Test method serializeReply.
@Test
public void serializeReply() throws Exception {
DHCP6 dhcp6 = new DHCP6();
dhcp6.setMsgType(DHCP6.MsgType.REPLY.value());
dhcp6.setTransactionId(XID_2);
List<Dhcp6Option> options = Lists.newArrayList();
// IA address
Dhcp6IaAddressOption iaAddressOption = new Dhcp6IaAddressOption();
iaAddressOption.setIp6Address(IA_ADDRESS);
iaAddressOption.setPreferredLifetime(PREFFERRED_LT_SERVER);
iaAddressOption.setValidLifetime(VALID_LT_SERVER);
// IA NA
Dhcp6IaNaOption iaNaOption = new Dhcp6IaNaOption();
iaNaOption.setIaId(IA_ID);
iaNaOption.setT1(T1_SERVER);
iaNaOption.setT2(T2_SERVER);
iaNaOption.setOptions(ImmutableList.of(iaAddressOption));
options.add(iaNaOption);
// Client ID
Dhcp6Duid duid = new Dhcp6Duid();
duid.setDuidType(Dhcp6Duid.DuidType.DUID_LLT);
duid.setHardwareType((short) 1);
duid.setDuidTime(CLIENT_DUID_TIME);
duid.setLinkLayerAddress(CLIENT_MAC.toBytes());
Dhcp6ClientIdOption clientIdOption = new Dhcp6ClientIdOption();
clientIdOption.setDuid(duid);
options.add(clientIdOption);
// Server ID
Dhcp6Option option = new Dhcp6Option();
option.setCode(DHCP6.OptionCode.SERVERID.value());
option.setLength((short) 14);
Dhcp6Duid serverDuid = new Dhcp6Duid();
serverDuid.setDuidType(Dhcp6Duid.DuidType.DUID_LLT);
serverDuid.setLinkLayerAddress(SERVER_MAC.toBytes());
serverDuid.setHardwareType((short) 1);
serverDuid.setDuidTime(0x211e5340);
option.setData(serverDuid.serialize());
options.add(option);
dhcp6.setOptions(options);
Dhcp6RelayOption relayOption = new Dhcp6RelayOption();
relayOption.setPayload(dhcp6);
UDP udp = new UDP();
udp.setSourcePort(UDP.DHCP_V6_SERVER_PORT);
udp.setDestinationPort(UDP.DHCP_V6_CLIENT_PORT);
udp.setPayload(dhcp6);
udp.setChecksum((short) 0xcb5a);
IPv6 ipv6 = new IPv6();
ipv6.setHopLimit((byte) 64);
ipv6.setSourceAddress(UPSTREAM_LL.toOctets());
ipv6.setDestinationAddress(CLIENT_LL.toOctets());
ipv6.setNextHeader(IPv6.PROTOCOL_UDP);
ipv6.setTrafficClass((byte) 0);
ipv6.setFlowLabel(0x000d935f);
ipv6.setPayload(udp);
Ethernet eth = new Ethernet();
eth.setDestinationMACAddress(CLIENT_MAC);
eth.setSourceMACAddress(UPSTREAM_MAC);
eth.setEtherType(Ethernet.TYPE_IPV6);
eth.setPayload(ipv6);
assertArrayEquals(Resources.toByteArray(Dhcp6RelayTest.class.getResource(REPLY)), eth.serialize());
}
use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class DhcpTest method testDeserializeAck.
/**
* Tests deserialize discover packet.
*/
@Test
public void testDeserializeAck() throws Exception {
byte[] data = Resources.toByteArray(Dhcp6RelayTest.class.getResource(ACK));
Ethernet eth = Ethernet.deserializer().deserialize(data, 0, data.length);
DHCP dhcp = (DHCP) eth.getPayload().getPayload().getPayload();
assertEquals(DHCP.OPCODE_REPLY, dhcp.getOpCode());
assertEquals(HW_TYPE, dhcp.getHardwareType());
assertEquals(HW_ADDR_LEN, dhcp.getHardwareAddressLength());
assertEquals(HOPS, dhcp.getHops());
assertEquals(XID, dhcp.getTransactionId());
assertEquals(SECS, dhcp.getSeconds());
assertEquals(FLAGS, dhcp.getFlags());
assertEquals(NO_IP, dhcp.getClientIPAddress());
assertEquals(CLIENT_IP.toInt(), dhcp.getYourIPAddress());
assertEquals(SERVER_IP.toInt(), dhcp.getServerIPAddress());
assertEquals(GW_IP.toInt(), dhcp.getGatewayIPAddress());
assertTrue(Arrays.equals(CLIENT_HW_ADDR.toBytes(), dhcp.getClientHardwareAddress()));
assertEquals(EMPTY, dhcp.getServerName());
assertEquals(EMPTY, dhcp.getBootFileName());
assertEquals(9, dhcp.getOptions().size());
DhcpOption option = dhcp.getOptions().get(0);
assertEquals(DHCP.DHCPOptionCode.OptionCode_MessageType.getValue(), option.code);
assertEquals(1, option.length);
assertEquals(DHCP.MsgType.DHCPACK.getValue(), (int) option.getData()[0]);
option = dhcp.getOptions().get(1);
assertEquals(DHCP.DHCPOptionCode.OptionCode_DHCPServerIp.getValue(), option.code);
assertEquals(4, option.length);
assertArrayEquals(SERVER_IP.toOctets(), option.getData());
option = dhcp.getOptions().get(2);
assertEquals(DHCP.DHCPOptionCode.OptionCode_LeaseTime.getValue(), option.code);
assertEquals(4, option.length);
assertArrayEquals(new byte[] { 0, 0, 2, 88 }, option.getData());
option = dhcp.getOptions().get(3);
assertEquals(DHCP.DHCPOptionCode.OptionCode_SubnetMask.getValue(), option.code);
assertEquals(4, option.length);
assertArrayEquals(SUBNET_MASK.toOctets(), option.getData());
option = dhcp.getOptions().get(4);
assertEquals(DHCP.DHCPOptionCode.OptionCode_RouterAddress.getValue(), option.code);
assertEquals(4, option.length);
assertArrayEquals(GW_IP.toOctets(), option.getData());
option = dhcp.getOptions().get(5);
assertEquals(DHCP.DHCPOptionCode.OptionCode_DomainName.getValue(), option.code);
assertEquals(13, option.length);
assertArrayEquals(DOMAIN_NAME.getBytes(Charsets.US_ASCII), option.getData());
option = dhcp.getOptions().get(6);
assertEquals(DHCP.DHCPOptionCode.OptionCode_DomainServer.getValue(), option.code);
assertEquals(8, option.length);
assertArrayEquals(ArrayUtils.addAll(DNS_1.toOctets(), DNS_2.toOctets()), option.getData());
option = dhcp.getOptions().get(7);
assertTrue(option instanceof DhcpRelayAgentOption);
DhcpRelayAgentOption relayAgentOption = (DhcpRelayAgentOption) option;
assertEquals(DHCP.DHCPOptionCode.OptionCode_CircuitID.getValue(), relayAgentOption.code);
assertEquals(12, relayAgentOption.length);
DhcpOption subOption = relayAgentOption.getSubOption(DhcpRelayAgentOption.RelayAgentInfoOptions.CIRCUIT_ID.getValue());
assertEquals(10, subOption.getLength());
assertArrayEquals(CIRCUIT_ID.getBytes(Charsets.US_ASCII), subOption.getData());
option = dhcp.getOptions().get(8);
assertEquals(DHCP.DHCPOptionCode.OptionCode_END.getValue(), option.code);
assertEquals(0, option.length);
}
use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class DhcpTest method testDeserializeRequest.
/**
* Tests deserialize discover packet.
*/
@Test
public void testDeserializeRequest() throws Exception {
byte[] data = Resources.toByteArray(Dhcp6RelayTest.class.getResource(REQUEST));
Ethernet eth = Ethernet.deserializer().deserialize(data, 0, data.length);
DHCP dhcp = (DHCP) eth.getPayload().getPayload().getPayload();
assertEquals(DHCP.OPCODE_REQUEST, dhcp.getOpCode());
assertEquals(HW_TYPE, dhcp.getHardwareType());
assertEquals(HW_ADDR_LEN, dhcp.getHardwareAddressLength());
assertEquals(HOPS, dhcp.getHops());
assertEquals(XID, dhcp.getTransactionId());
assertEquals(SECS, dhcp.getSeconds());
assertEquals(FLAGS, dhcp.getFlags());
assertEquals(NO_IP, dhcp.getClientIPAddress());
assertEquals(NO_IP, dhcp.getYourIPAddress());
assertEquals(NO_IP, dhcp.getServerIPAddress());
assertEquals(GW_IP.toInt(), dhcp.getGatewayIPAddress());
assertTrue(Arrays.equals(CLIENT_HW_ADDR.toBytes(), dhcp.getClientHardwareAddress()));
assertEquals(EMPTY, dhcp.getServerName());
assertEquals(EMPTY, dhcp.getBootFileName());
assertEquals(7, dhcp.getOptions().size());
DhcpOption option = dhcp.getOptions().get(0);
assertEquals(DHCP.DHCPOptionCode.OptionCode_MessageType.getValue(), option.code);
assertEquals(1, option.length);
assertEquals(DHCP.MsgType.DHCPREQUEST.getValue(), (int) option.getData()[0]);
option = dhcp.getOptions().get(1);
assertEquals(DHCP.DHCPOptionCode.OptionCode_DHCPServerIp.getValue(), option.code);
assertEquals(4, option.length);
assertArrayEquals(SERVER_IP.toOctets(), option.getData());
option = dhcp.getOptions().get(2);
assertEquals(DHCP.DHCPOptionCode.OptionCode_RequestedIP.getValue(), option.code);
assertEquals(4, option.length);
assertArrayEquals(CLIENT_IP.toOctets(), option.getData());
option = dhcp.getOptions().get(3);
assertEquals(DHCP.DHCPOptionCode.OptionCode_HostName.getValue(), option.code);
assertEquals(9, option.length);
assertArrayEquals(HOSTNAME.getBytes(Charsets.US_ASCII), option.getData());
option = dhcp.getOptions().get(4);
assertEquals(DHCP.DHCPOptionCode.OptionCode_RequestedParameters.getValue(), option.code);
assertEquals(13, option.length);
assertArrayEquals(new byte[] { 1, 28, 2, 3, 15, 6, 119, 12, 44, 47, 26, 121, 42 }, option.getData());
option = dhcp.getOptions().get(5);
assertTrue(option instanceof DhcpRelayAgentOption);
DhcpRelayAgentOption relayAgentOption = (DhcpRelayAgentOption) option;
assertEquals(DHCP.DHCPOptionCode.OptionCode_CircuitID.getValue(), relayAgentOption.code);
assertEquals(12, relayAgentOption.length);
DhcpOption subOption = relayAgentOption.getSubOption(DhcpRelayAgentOption.RelayAgentInfoOptions.CIRCUIT_ID.getValue());
assertEquals(10, subOption.getLength());
assertArrayEquals(CIRCUIT_ID.getBytes(Charsets.US_ASCII), subOption.getData());
option = dhcp.getOptions().get(6);
assertEquals(DHCP.DHCPOptionCode.OptionCode_END.getValue(), option.code);
assertEquals(0, option.length);
}
use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class OpenFlowCorePacketContext method send.
@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");
}
}
}
}
Aggregations