Search in sources :

Example 11 with IPv6

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);
}
Also used : IPv6(org.onlab.packet.IPv6) Test(org.junit.Test)

Example 12 with IPv6

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));
}
Also used : IPv6(org.onlab.packet.IPv6) Test(org.junit.Test)

Example 13 with IPv6

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);
}
Also used : IPv6(org.onlab.packet.IPv6) Test(org.junit.Test)

Example 14 with IPv6

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());
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) IPv6(org.onlab.packet.IPv6) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) ConnectPoint(org.onosproject.net.ConnectPoint) OutboundPacket(org.onosproject.net.packet.OutboundPacket) InterfaceService(org.onosproject.net.intf.InterfaceService) Ethernet(org.onlab.packet.Ethernet) NeighborSolicitation(org.onlab.packet.ndp.NeighborSolicitation) PortNumber(org.onosproject.net.PortNumber) Interface(org.onosproject.net.intf.Interface) Test(org.junit.Test)

Example 15 with IPv6

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;
}
Also used : Dhcp6IaPdOption(org.onlab.packet.dhcp.Dhcp6IaPdOption) DeviceService(org.onosproject.net.device.DeviceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) IgnoreDhcpConfig(org.onosproject.dhcprelay.config.IgnoreDhcpConfig) ApplicationId(org.onosproject.core.ApplicationId) Dhcp6IaNaOption(org.onlab.packet.dhcp.Dhcp6IaNaOption) Dhcp6IaTaOption(org.onlab.packet.dhcp.Dhcp6IaTaOption) Ip6Address(org.onlab.packet.Ip6Address) DhcpRelayStore(org.onosproject.dhcprelay.store.DhcpRelayStore) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) MsgType(org.onlab.packet.DHCP6.MsgType) PacketService(org.onosproject.net.packet.PacketService) DeviceId(org.onosproject.net.DeviceId) DhcpServerConfig(org.onosproject.dhcprelay.config.DhcpServerConfig) LEARN_ROUTE_FROM_LEASE_QUERY_DEFAULT(org.onosproject.dhcprelay.OsgiPropertyConstants.LEARN_ROUTE_FROM_LEASE_QUERY_DEFAULT) Dictionary(java.util.Dictionary) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Pipeliner(org.onosproject.net.behaviour.Pipeliner) REMOVE(org.onosproject.net.flowobjective.Objective.Operation.REMOVE) DhcpFpmPrefixStore(org.onosproject.dhcprelay.store.DhcpFpmPrefixStore) HostProviderRegistry(org.onosproject.net.host.HostProviderRegistry) Tools(org.onlab.util.Tools) RouteStore(org.onosproject.routeservice.RouteStore) Host(org.onosproject.net.Host) ComponentContext(org.osgi.service.component.ComponentContext) LEARN_ROUTE_FROM_LEASE_QUERY(org.onosproject.dhcprelay.OsgiPropertyConstants.LEARN_ROUTE_FROM_LEASE_QUERY) HostListener(org.onosproject.net.host.HostListener) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) Multimaps(com.google.common.collect.Multimaps) ArrayList(java.util.ArrayList) Dhcp6InterfaceIdOption(org.onlab.packet.dhcp.Dhcp6InterfaceIdOption) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) FpmRecord(org.onosproject.routing.fpm.api.FpmRecord) Dhcp6LeaseQueryOption(org.onlab.packet.dhcp.Dhcp6LeaseQueryOption) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) TpPort(org.onlab.packet.TpPort) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) BasePacket(org.onlab.packet.BasePacket) Executor(java.util.concurrent.Executor) HostProvider(org.onosproject.net.host.HostProvider) VlanId(org.onlab.packet.VlanId) ProviderId(org.onosproject.net.provider.ProviderId) Dhcp6IaAddressOption(org.onlab.packet.dhcp.Dhcp6IaAddressOption) IPv6(org.onlab.packet.IPv6) DHCP6(org.onlab.packet.DHCP6) HexString(org.onlab.util.HexString) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) Dhcp6Duid(org.onlab.packet.dhcp.Dhcp6Duid) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Route(org.onosproject.routeservice.Route) HostLocation(org.onosproject.net.HostLocation) Interface(org.onosproject.net.intf.Interface) CoreService(org.onosproject.core.CoreService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) Dhcp6ClientIdOption(org.onlab.packet.dhcp.Dhcp6ClientIdOption) ByteBuffer(java.nio.ByteBuffer) Ethernet(org.onlab.packet.Ethernet) HostProviderService(org.onosproject.net.host.HostProviderService) HashMultimap(com.google.common.collect.HashMultimap) Dhcp6IaPrefixOption(org.onlab.packet.dhcp.Dhcp6IaPrefixOption) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) ImmutableSet(com.google.common.collect.ImmutableSet) Device(org.onosproject.net.Device) Collection(java.util.Collection) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) PacketContext(org.onosproject.net.packet.PacketContext) Optional(java.util.Optional) HostDescription(org.onosproject.net.host.HostDescription) IpPrefix(org.onlab.packet.IpPrefix) Dhcp6ClientDataOption(org.onlab.packet.dhcp.Dhcp6ClientDataOption) ADD(org.onosproject.net.flowobjective.Objective.Operation.ADD) Multimap(com.google.common.collect.Multimap) Dhcp6RelayOption(org.onlab.packet.dhcp.Dhcp6RelayOption) DhcpRelayCountersStore(org.onosproject.dhcprelay.store.DhcpRelayCountersStore) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) OutboundPacket(org.onosproject.net.packet.OutboundPacket) Activate(org.osgi.service.component.annotations.Activate) HostEvent(org.onosproject.net.host.HostEvent) HostId(org.onosproject.net.HostId) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) Semaphore(java.util.concurrent.Semaphore) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Dhcp6Option(org.onlab.packet.dhcp.Dhcp6Option) UDP(org.onlab.packet.UDP) DhcpHandler(org.onosproject.dhcprelay.api.DhcpHandler) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Modified(org.osgi.service.component.annotations.Modified) PacketPriority(org.onosproject.net.packet.PacketPriority) Reference(org.osgi.service.component.annotations.Reference) Ip6Address(org.onlab.packet.Ip6Address) Dhcp6IaPrefixOption(org.onlab.packet.dhcp.Dhcp6IaPrefixOption) Dhcp6IaPdOption(org.onlab.packet.dhcp.Dhcp6IaPdOption) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

IPv6 (org.onlab.packet.IPv6)48 Ethernet (org.onlab.packet.Ethernet)41 Test (org.junit.Test)27 ICMP6 (org.onlab.packet.ICMP6)22 UDP (org.onlab.packet.UDP)18 DHCP6 (org.onlab.packet.DHCP6)17 ConnectPoint (org.onosproject.net.ConnectPoint)12 Ip6Address (org.onlab.packet.Ip6Address)11 Interface (org.onosproject.net.intf.Interface)11 MacAddress (org.onlab.packet.MacAddress)10 DeviceId (org.onosproject.net.DeviceId)10 OutboundPacket (org.onosproject.net.packet.OutboundPacket)10 IpAddress (org.onlab.packet.IpAddress)9 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)9 VlanId (org.onlab.packet.VlanId)8 Logger (org.slf4j.Logger)8 ByteBuffer (java.nio.ByteBuffer)7 HostService (org.onosproject.net.host.HostService)7 InterfaceService (org.onosproject.net.intf.InterfaceService)7 LoggerFactory (org.slf4j.LoggerFactory)7