use of org.onlab.packet.IPv6 in project onos by opennetworkinglab.
the class IPv6Test method testSerialize.
/**
* Tests serialize and setters.
*/
@Test
public void testSerialize() {
IPv6 ipv6 = new IPv6();
ipv6.setPayload(udp);
ipv6.setVersion((byte) 6);
ipv6.setTrafficClass((byte) 0x93);
ipv6.setFlowLabel(0x13579);
ipv6.setNextHeader(PROTOCOL_UDP);
ipv6.setHopLimit((byte) 32);
ipv6.setSourceAddress(SOURCE_ADDRESS);
ipv6.setDestinationAddress(DESTINATION_ADDRESS);
assertArrayEquals(ipv6.serialize(), bytePacket);
}
use of org.onlab.packet.IPv6 in project onos by opennetworkinglab.
the class IPv6Test method testEqual.
/**
* Tests comparator.
*/
@Test
public void testEqual() {
IPv6 packet1 = new IPv6();
packet1.setPayload(udp);
packet1.setVersion((byte) 6);
packet1.setTrafficClass((byte) 0x93);
packet1.setFlowLabel(0x13579);
packet1.setNextHeader(PROTOCOL_UDP);
packet1.setHopLimit((byte) 32);
packet1.setSourceAddress(SOURCE_ADDRESS);
packet1.setDestinationAddress(DESTINATION_ADDRESS);
IPv6 packet2 = new IPv6();
packet2.setPayload(udp);
packet2.setVersion((byte) 6);
packet2.setTrafficClass((byte) 0x93);
packet2.setFlowLabel(0x13579);
packet2.setNextHeader(PROTOCOL_UDP);
packet2.setHopLimit((byte) 32);
packet2.setSourceAddress(DESTINATION_ADDRESS);
packet2.setDestinationAddress(SOURCE_ADDRESS);
assertTrue(packet1.equals(packet1));
assertFalse(packet1.equals(packet2));
}
use of org.onlab.packet.IPv6 in project onos by opennetworkinglab.
the class IPv6Test method testDeserialize.
/**
* Tests deserialize and getters.
*/
@Test
public void testDeserialize() throws DeserializationException {
IPv6 ipv6 = deserializer.deserialize(bytePacket, 0, bytePacket.length);
assertThat(ipv6.getVersion(), is((byte) 6));
assertThat(ipv6.getTrafficClass(), is((byte) 0x93));
assertThat(ipv6.getFlowLabel(), is(0x13579));
assertThat(ipv6.getNextHeader(), is(PROTOCOL_UDP));
assertThat(ipv6.getHopLimit(), is((byte) 32));
assertArrayEquals(ipv6.getSourceAddress(), SOURCE_ADDRESS);
assertArrayEquals(ipv6.getDestinationAddress(), DESTINATION_ADDRESS);
}
use of org.onlab.packet.IPv6 in project onos by opennetworkinglab.
the class HostMonitorTest method testMonitorIpv6HostDoesNotExist.
@Test
public void testMonitorIpv6HostDoesNotExist() throws Exception {
HostManager hostManager = createMock(HostManager.class);
DeviceId devId = DeviceId.deviceId("fake");
Device device = createMock(Device.class);
expect(device.id()).andReturn(devId).anyTimes();
replay(device);
PortNumber portNum = PortNumber.portNumber(2L);
Port port = createMock(Port.class);
expect(port.number()).andReturn(portNum).anyTimes();
expect(port.isEnabled()).andReturn(true).anyTimes();
replay(port);
TestDeviceService deviceService = new TestDeviceService();
deviceService.addDevice(device, Collections.singleton(port));
ConnectPoint cp = new ConnectPoint(devId, portNum);
expect(hostManager.getHostsByIp(TARGET_IPV6_ADDR)).andReturn(Collections.emptySet()).anyTimes();
replay(hostManager);
InterfaceService interfaceService = createMock(InterfaceService.class);
expect(interfaceService.getMatchingInterfaces(TARGET_IPV6_ADDR)).andReturn(Collections.singleton(new Interface(Interface.NO_INTERFACE_NAME, cp, Collections.singletonList(IA2), sourceMac2, VlanId.NONE))).anyTimes();
replay(interfaceService);
TestPacketService packetService = new TestPacketService();
// Run the test
hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService, deviceService);
hostMonitor.addMonitoringFor(TARGET_IPV6_ADDR);
hostMonitor.run();
// Check that a packet was sent to our PacketService and that it has
// the properties we expect
assertEquals(2, packetService.packets.size());
OutboundPacket packet = packetService.packets.get(0);
// Check the output port is correct
assertEquals(1, packet.treatment().immediate().size());
Instruction instruction = packet.treatment().immediate().get(0);
assertTrue(instruction instanceof OutputInstruction);
OutputInstruction oi = (OutputInstruction) instruction;
assertEquals(portNum, oi.port());
// Check the output packet is correct (well the important bits anyway)
final byte[] pktData = new byte[packet.data().remaining()];
packet.data().get(pktData);
Ethernet eth = Ethernet.deserializer().deserialize(pktData, 0, pktData.length);
assertEquals(Ethernet.VLAN_UNTAGGED, eth.getVlanID());
IPv6 ipv6 = (IPv6) eth.getPayload();
assertArrayEquals(SOURCE_IPV6_ADDR.toOctets(), ipv6.getSourceAddress());
NeighborSolicitation ns = (NeighborSolicitation) ipv6.getPayload().getPayload();
assertArrayEquals(sourceMac2.toBytes(), ns.getOptions().get(0).data());
assertArrayEquals(TARGET_IPV6_ADDR.toOctets(), ns.getTargetAddress());
}
use of org.onlab.packet.IPv6 in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method extractPrefix.
/**
* extract from dhcp6 packet Prefix prefix provided by dhcp server.
*
* @param dhcp6 the dhcp6 payload
* @return IpPrefix Prefix Delegation prefix, or null if not exists.
*/
private PdPrefixInfo extractPrefix(DHCP6 dhcp6) {
log.debug("extractPrefix enters {}", dhcp6);
// extract prefix
PdPrefixInfo pdPrefixInfo = new PdPrefixInfo();
Ip6Address prefixAddress = null;
// Extract IPv6 prefix from IA PD option
Optional<Dhcp6IaPdOption> iaPdOption = dhcp6.getOptions().stream().filter(opt -> opt instanceof Dhcp6IaPdOption).map(opt -> (Dhcp6IaPdOption) opt).findFirst();
Optional<Dhcp6IaPrefixOption> iaPrefixOption;
if (iaPdOption.isPresent()) {
log.debug("IA_PD option found {}", iaPdOption);
iaPrefixOption = iaPdOption.get().getOptions().stream().filter(opt -> opt instanceof Dhcp6IaPrefixOption).map(opt -> (Dhcp6IaPrefixOption) opt).findFirst();
} else {
log.debug("IA_PD option NOT found");
iaPrefixOption = Optional.empty();
}
if (iaPrefixOption.isPresent()) {
log.debug("IAPrefix Option within IA_PD option found {}", iaPrefixOption);
prefixAddress = iaPrefixOption.get().getIp6Prefix();
int prefixLen = (int) iaPrefixOption.get().getPrefixLength();
log.debug("Prefix length is {} bits", prefixLen);
pdPrefixInfo.pdPrefix = IpPrefix.valueOf(prefixAddress, prefixLen);
pdPrefixInfo.prefTime = iaPrefixOption.get().getPreferredLifetime();
} else {
log.debug("Can't find IPv6 prefix from DHCPv6 {}", dhcp6);
return null;
}
return pdPrefixInfo;
}
Aggregations