Search in sources :

Example 1 with IPv6

use of org.onlab.packet.IPv6 in project onos by opennetworkinglab.

the class DirectHostManager method handle.

private boolean handle(Ethernet eth) {
    checkNotNull(eth);
    // skip them.
    if (!enabled || (eth.getEtherType() != Ethernet.TYPE_IPV6 && eth.getEtherType() != Ethernet.TYPE_IPV4)) {
        return false;
    }
    // According to the type we set the destIp.
    IpAddress dstIp;
    if (eth.getEtherType() == Ethernet.TYPE_IPV4) {
        IPv4 ip = (IPv4) eth.getPayload();
        dstIp = IpAddress.valueOf(ip.getDestinationAddress());
    } else {
        IPv6 ip = (IPv6) eth.getPayload();
        dstIp = IpAddress.valueOf(INET6, ip.getDestinationAddress());
    }
    // Looking for a candidate output port.
    Interface egressInterface = interfaceService.getMatchingInterface(dstIp);
    if (egressInterface == null) {
        log.info("No egress interface found for {}", dstIp);
        return false;
    }
    // Looking for the destination mac.
    Optional<Host> host = hostService.getHostsByIp(dstIp).stream().filter(h -> h.location().equals(egressInterface.connectPoint())).filter(h -> h.vlan().equals(egressInterface.vlan())).findAny();
    // and we queue the packets waiting for a destination.
    if (host.isPresent()) {
        transformAndSend((IP) eth.getPayload(), eth.getEtherType(), egressInterface, host.get().mac());
    } else {
        hostService.startMonitoringIp(dstIp);
        ipPacketCache.asMap().compute(dstIp, (ip, queue) -> {
            if (queue == null) {
                queue = new ConcurrentLinkedQueue<>();
            }
            queue.add((IP) eth.getPayload());
            return queue;
        });
    }
    return true;
}
Also used : ENABLED(org.onosproject.routing.impl.OsgiPropertyConstants.ENABLED) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) Interface(org.onosproject.net.intf.Interface) CoreService(org.onosproject.core.CoreService) ComponentContext(org.osgi.service.component.ComponentContext) LoggerFactory(org.slf4j.LoggerFactory) INET6(org.onlab.packet.IpAddress.Version.INET6) HostListener(org.onosproject.net.host.HostListener) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ApplicationId(org.onosproject.core.ApplicationId) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) ENABLED_DEFAULT(org.onosproject.routing.impl.OsgiPropertyConstants.ENABLED_DEFAULT) VlanId(org.onlab.packet.VlanId) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) PacketService(org.onosproject.net.packet.PacketService) IPv6(org.onlab.packet.IPv6) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) EthType(org.onlab.packet.EthType) IPv4(org.onlab.packet.IPv4) IP(org.onlab.packet.IP) PacketContext(org.onosproject.net.packet.PacketContext) Modified(org.osgi.service.component.annotations.Modified) Optional(java.util.Optional) MacAddress(org.onlab.packet.MacAddress) CacheBuilder(com.google.common.cache.CacheBuilder) PacketPriority(org.onosproject.net.packet.PacketPriority) Queue(java.util.Queue) Cache(com.google.common.cache.Cache) Reference(org.osgi.service.component.annotations.Reference) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) IPv6(org.onlab.packet.IPv6) IPv4(org.onlab.packet.IPv4) IpAddress(org.onlab.packet.IpAddress) Host(org.onosproject.net.Host) Interface(org.onosproject.net.intf.Interface)

Example 2 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)

Example 3 with IPv6

use of org.onlab.packet.IPv6 in project onos by opennetworkinglab.

the class Dhcp6HandlerUtil method processLQ6PacketFromServer.

/**
 * process the LQ reply packet from dhcp server.
 *
 * @param defaultServerInfoList default server list
 * @param indirectServerInfoList default indirect server list
 * @param serverInterface server interface
 * @param interfaceService interface service
 * @param hostService host service
 * @param context packet context
 * @param receivedPacket server ethernet packet
 * @param recevingInterfaces set of server side interfaces
 * @return a packet ready to be sent to relevant output interface
 */
public static InternalPacket processLQ6PacketFromServer(List<DhcpServerInfo> defaultServerInfoList, List<DhcpServerInfo> indirectServerInfoList, Interface serverInterface, InterfaceService interfaceService, HostService hostService, PacketContext context, Ethernet receivedPacket, Set<Interface> recevingInterfaces) {
    // get dhcp6 header.
    Ethernet etherReply = (Ethernet) receivedPacket.clone();
    IPv6 ipv6Packet = (IPv6) etherReply.getPayload();
    UDP udpPacket = (UDP) ipv6Packet.getPayload();
    DHCP6 lq6Reply = (DHCP6) udpPacket.getPayload();
    // TODO: refactor
    ConnectPoint receivedFrom = context.inPacket().receivedFrom();
    DeviceId receivedFromDevice = receivedFrom.deviceId();
    DhcpServerInfo serverInfo;
    Ip6Address dhcpServerIp = null;
    ConnectPoint dhcpServerConnectPoint = null;
    MacAddress dhcpConnectMac = null;
    VlanId dhcpConnectVlan = null;
    Ip6Address dhcpGatewayIp = null;
    // todo: refactor
    Ip6Address indirectDhcpServerIp = null;
    ConnectPoint indirectDhcpServerConnectPoint = null;
    MacAddress indirectDhcpConnectMac = null;
    VlanId indirectDhcpConnectVlan = null;
    Ip6Address indirectDhcpGatewayIp = null;
    Ip6Address indirectRelayAgentIpFromCfg = null;
    if (!defaultServerInfoList.isEmpty()) {
        serverInfo = defaultServerInfoList.get(0);
        dhcpConnectMac = serverInfo.getDhcpConnectMac().orElse(null);
        dhcpGatewayIp = serverInfo.getDhcpGatewayIp6().orElse(null);
        dhcpServerIp = serverInfo.getDhcpServerIp6().orElse(null);
        dhcpServerConnectPoint = serverInfo.getDhcpServerConnectPoint().orElse(null);
        dhcpConnectVlan = serverInfo.getDhcpConnectVlan().orElse(null);
    }
    if (!indirectServerInfoList.isEmpty()) {
        serverInfo = indirectServerInfoList.get(0);
        indirectDhcpConnectMac = serverInfo.getDhcpConnectMac().orElse(null);
        indirectDhcpGatewayIp = serverInfo.getDhcpGatewayIp6().orElse(null);
        indirectDhcpServerIp = serverInfo.getDhcpServerIp6().orElse(null);
        indirectDhcpServerConnectPoint = serverInfo.getDhcpServerConnectPoint().orElse(null);
        indirectDhcpConnectVlan = serverInfo.getDhcpConnectVlan().orElse(null);
        indirectRelayAgentIpFromCfg = serverInfo.getRelayAgentIp6(receivedFromDevice).orElse(null);
    }
    Boolean directConnFlag = directlyConnected(lq6Reply);
    ConnectPoint inPort = context.inPacket().receivedFrom();
    if ((directConnFlag || indirectDhcpServerIp == null) && !inPort.equals(dhcpServerConnectPoint)) {
        log.warn("Receiving port {} is not the same as server connect point {} for direct or indirect-null", inPort, dhcpServerConnectPoint);
        return null;
    }
    if (!directConnFlag && indirectDhcpServerIp != null && !inPort.equals(indirectDhcpServerConnectPoint)) {
        log.warn("Receiving port {} is not the same as server connect point {} for indirect", inPort, indirectDhcpServerConnectPoint);
        return null;
    }
    Ip6Address nextHopIP = Ip6Address.valueOf(ipv6Packet.getDestinationAddress());
    // use hosts store to find out the next hop mac and connection point
    Set<Host> hosts = hostService.getHostsByIp(nextHopIP);
    Host host;
    if (!hosts.isEmpty()) {
        host = hosts.iterator().next();
    } else {
        log.warn("Host {} is not in store", nextHopIP);
        return null;
    }
    HostLocation hl = host.location();
    // iterator().next());
    String clientConnectionPointStr = hl.toString();
    ConnectPoint clientConnectionPoint = ConnectPoint.deviceConnectPoint(clientConnectionPointStr);
    VlanId originalPacketVlanId = VlanId.vlanId(etherReply.getVlanID());
    Interface iface;
    iface = interfaceService.getInterfacesByPort(clientConnectionPoint).stream().filter(iface1 -> interfaceContainsVlan(iface1, originalPacketVlanId)).findFirst().orElse(null);
    etherReply.setSourceMACAddress(iface.mac());
    etherReply.setDestinationMACAddress(host.mac());
    // workaround for a bug where core sends src port as 547 (server)
    udpPacket.setDestinationPort(UDP.DHCP_V6_SERVER_PORT);
    udpPacket.setPayload(lq6Reply);
    udpPacket.resetChecksum();
    ipv6Packet.setPayload(udpPacket);
    etherReply.setPayload(ipv6Packet);
    return InternalPacket.internalPacket(etherReply, clientConnectionPoint);
}
Also used : UDP(org.onlab.packet.UDP) HostLocation(org.onosproject.net.HostLocation) Host(org.onosproject.net.Host) Interface(org.onosproject.net.intf.Interface) LoggerFactory(org.slf4j.LoggerFactory) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) Dhcp6ClientIdOption(org.onlab.packet.dhcp.Dhcp6ClientIdOption) Dhcp6RelayOption(org.onlab.packet.dhcp.Dhcp6RelayOption) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) Ethernet(org.onlab.packet.Ethernet) DhcpRelayCounters(org.onosproject.dhcprelay.store.DhcpRelayCounters) IpAddress(org.onlab.packet.IpAddress) BasePacket(org.onlab.packet.BasePacket) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) Ip6Address(org.onlab.packet.Ip6Address) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Dhcp6Option(org.onlab.packet.dhcp.Dhcp6Option) Set(java.util.Set) MsgType(org.onlab.packet.DHCP6.MsgType) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) UDP(org.onlab.packet.UDP) IPv6(org.onlab.packet.IPv6) DHCP6(org.onlab.packet.DHCP6) List(java.util.List) HexString(org.onlab.util.HexString) PacketContext(org.onosproject.net.packet.PacketContext) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) IPv6(org.onlab.packet.IPv6) DeviceId(org.onosproject.net.DeviceId) Host(org.onosproject.net.Host) HexString(org.onlab.util.HexString) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) Ip6Address(org.onlab.packet.Ip6Address) Ethernet(org.onlab.packet.Ethernet) HostLocation(org.onosproject.net.HostLocation) DHCP6(org.onlab.packet.DHCP6) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) VlanId(org.onlab.packet.VlanId) Interface(org.onosproject.net.intf.Interface)

Example 4 with IPv6

use of org.onlab.packet.IPv6 in project onos by opennetworkinglab.

the class Dhcp6HandlerUtil method buildDhcp6PacketFromClient.

/**
 * build the DHCP6 solicit/request packet with gatewayip.
 *
 * @param context packet context
 * @param clientPacket client ethernet packet
 * @param clientInterfaces set of client side interfaces
 * @param serverInfo target server which a packet is generated for
 * @param serverInterface target server interface
 * @return ethernet packet with dhcp6 packet info
 */
public static Ethernet buildDhcp6PacketFromClient(PacketContext context, Ethernet clientPacket, Set<Interface> clientInterfaces, DhcpServerInfo serverInfo, Interface serverInterface) {
    ConnectPoint receivedFrom = context.inPacket().receivedFrom();
    DeviceId receivedFromDevice = receivedFrom.deviceId();
    Ip6Address relayAgentIp = getRelayAgentIPv6Address(clientInterfaces);
    MacAddress relayAgentMac = clientInterfaces.iterator().next().mac();
    if (relayAgentIp == null || relayAgentMac == null) {
        log.warn("Missing DHCP relay agent interface Ipv6 addr config for " + "packet from client on port: {}. Aborting packet processing", clientInterfaces.iterator().next().connectPoint());
        return null;
    }
    IPv6 clientIpv6 = (IPv6) clientPacket.getPayload();
    UDP clientUdp = (UDP) clientIpv6.getPayload();
    DHCP6 clientDhcp6 = (DHCP6) clientUdp.getPayload();
    boolean directConnFlag = directlyConnected(clientDhcp6);
    Ip6Address serverIpFacing = getFirstIpFromInterface(serverInterface);
    if (serverIpFacing == null || serverInterface.mac() == null) {
        log.warn("No IP v6 address for server Interface {}", serverInterface);
        return null;
    }
    Ethernet etherReply = clientPacket.duplicate();
    etherReply.setSourceMACAddress(serverInterface.mac());
    // set default info and replace with indirect if available later on.
    if (serverInfo.getDhcpConnectMac().isPresent()) {
        etherReply.setDestinationMACAddress(serverInfo.getDhcpConnectMac().get());
    }
    if (serverInfo.getDhcpConnectVlan().isPresent()) {
        etherReply.setVlanID(serverInfo.getDhcpConnectVlan().get().toShort());
    }
    IPv6 ipv6Packet = (IPv6) etherReply.getPayload();
    byte[] peerAddress = clientIpv6.getSourceAddress();
    ipv6Packet.setSourceAddress(serverIpFacing.toOctets());
    ipv6Packet.setDestinationAddress(serverInfo.getDhcpServerIp6().get().toOctets());
    UDP udpPacket = (UDP) ipv6Packet.getPayload();
    udpPacket.setSourcePort(UDP.DHCP_V6_SERVER_PORT);
    DHCP6 dhcp6Packet = (DHCP6) udpPacket.getPayload();
    byte[] dhcp6PacketByte = dhcp6Packet.serialize();
    DHCP6 dhcp6Relay = new DHCP6();
    dhcp6Relay.setMsgType(DHCP6.MsgType.RELAY_FORW.value());
    if (directConnFlag) {
        dhcp6Relay.setLinkAddress(relayAgentIp.toOctets());
    } else {
        if (isServerIpEmpty(serverInfo)) {
            log.warn("indirect DhcpServerIp empty... use default server ");
        } else {
            // Check if mac is obtained for valid server ip
            if (isConnectMacEmpty(serverInfo, clientInterfaces)) {
                log.warn("indirect Dhcp ConnectMac empty ...");
                return null;
            }
            etherReply.setDestinationMACAddress(serverInfo.getDhcpConnectMac().get());
            etherReply.setVlanID(serverInfo.getDhcpConnectVlan().get().toShort());
            ipv6Packet.setDestinationAddress(serverInfo.getDhcpServerIp6().get().toOctets());
        }
        if (!serverInfo.getRelayAgentIp6(receivedFromDevice).isPresent()) {
            log.debug("indirect connection: relayAgentIp NOT availale from config file! Use dynamic. {}", HexString.toHexString(relayAgentIp.toOctets(), ":"));
            serverIpFacing = relayAgentIp;
        } else {
            serverIpFacing = serverInfo.getRelayAgentIp6(receivedFromDevice).get();
        }
        log.debug("Source IP address set as relay agent IP with value: {}", serverIpFacing);
        dhcp6Relay.setLinkAddress(serverIpFacing.toOctets());
        ipv6Packet.setSourceAddress(serverIpFacing.toOctets());
    }
    // peer address: address of the client or relay agent from which the message to be relayed was received.
    dhcp6Relay.setPeerAddress(peerAddress);
    // directly connected case, hop count is zero; otherwise, hop count + 1
    if (directConnFlag) {
        dhcp6Relay.setHopCount((byte) 0);
    } else {
        dhcp6Relay.setHopCount((byte) (dhcp6Packet.getHopCount() + 1));
    }
    List<Dhcp6Option> options = new ArrayList<>();
    addDhcp6OptionsFromClient(options, dhcp6PacketByte, context, clientPacket);
    dhcp6Relay.setOptions(options);
    udpPacket.setPayload(dhcp6Relay);
    udpPacket.resetChecksum();
    ipv6Packet.setPayload(udpPacket);
    ipv6Packet.setHopLimit((byte) 64);
    etherReply.setPayload(ipv6Packet);
    return etherReply;
}
Also used : UDP(org.onlab.packet.UDP) IPv6(org.onlab.packet.IPv6) DeviceId(org.onosproject.net.DeviceId) ArrayList(java.util.ArrayList) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) Ip6Address(org.onlab.packet.Ip6Address) Dhcp6Option(org.onlab.packet.dhcp.Dhcp6Option) Ethernet(org.onlab.packet.Ethernet) DHCP6(org.onlab.packet.DHCP6)

Example 5 with IPv6

use of org.onlab.packet.IPv6 in project onos by opennetworkinglab.

the class ReactiveForwarding method installRule.

// Install a rule forwarding the packet to the specified port.
private void installRule(PacketContext context, PortNumber portNumber, ReactiveForwardMetrics macMetrics) {
    // 
    // We don't support (yet) buffer IDs in the Flow Service so
    // packet out first.
    // 
    Ethernet inPkt = context.inPacket().parsed();
    TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
    // If PacketOutOnly or ARP packet than forward directly to output port
    if (packetOutOnly || inPkt.getEtherType() == Ethernet.TYPE_ARP) {
        packetOut(context, portNumber, macMetrics);
        return;
    }
    // 
    if (matchDstMacOnly) {
        selectorBuilder.matchEthDst(inPkt.getDestinationMAC());
    } else {
        selectorBuilder.matchInPort(context.inPacket().receivedFrom().port()).matchEthSrc(inPkt.getSourceMAC()).matchEthDst(inPkt.getDestinationMAC());
        // If configured Match Vlan ID
        if (matchVlanId && inPkt.getVlanID() != Ethernet.VLAN_UNTAGGED) {
            selectorBuilder.matchVlanId(VlanId.vlanId(inPkt.getVlanID()));
        }
        // 
        if (matchIpv4Address && inPkt.getEtherType() == Ethernet.TYPE_IPV4) {
            IPv4 ipv4Packet = (IPv4) inPkt.getPayload();
            byte ipv4Protocol = ipv4Packet.getProtocol();
            Ip4Prefix matchIp4SrcPrefix = Ip4Prefix.valueOf(ipv4Packet.getSourceAddress(), Ip4Prefix.MAX_MASK_LENGTH);
            Ip4Prefix matchIp4DstPrefix = Ip4Prefix.valueOf(ipv4Packet.getDestinationAddress(), Ip4Prefix.MAX_MASK_LENGTH);
            selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(matchIp4SrcPrefix).matchIPDst(matchIp4DstPrefix);
            if (matchIpv4Dscp) {
                byte dscp = ipv4Packet.getDscp();
                byte ecn = ipv4Packet.getEcn();
                selectorBuilder.matchIPDscp(dscp).matchIPEcn(ecn);
            }
            if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_TCP) {
                TCP tcpPacket = (TCP) ipv4Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv4Protocol).matchTcpSrc(TpPort.tpPort(tcpPacket.getSourcePort())).matchTcpDst(TpPort.tpPort(tcpPacket.getDestinationPort()));
            }
            if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_UDP) {
                UDP udpPacket = (UDP) ipv4Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv4Protocol).matchUdpSrc(TpPort.tpPort(udpPacket.getSourcePort())).matchUdpDst(TpPort.tpPort(udpPacket.getDestinationPort()));
            }
            if (matchIcmpFields && ipv4Protocol == IPv4.PROTOCOL_ICMP) {
                ICMP icmpPacket = (ICMP) ipv4Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv4Protocol).matchIcmpType(icmpPacket.getIcmpType()).matchIcmpCode(icmpPacket.getIcmpCode());
            }
        }
        // 
        if (matchIpv6Address && inPkt.getEtherType() == Ethernet.TYPE_IPV6) {
            IPv6 ipv6Packet = (IPv6) inPkt.getPayload();
            byte ipv6NextHeader = ipv6Packet.getNextHeader();
            Ip6Prefix matchIp6SrcPrefix = Ip6Prefix.valueOf(ipv6Packet.getSourceAddress(), Ip6Prefix.MAX_MASK_LENGTH);
            Ip6Prefix matchIp6DstPrefix = Ip6Prefix.valueOf(ipv6Packet.getDestinationAddress(), Ip6Prefix.MAX_MASK_LENGTH);
            selectorBuilder.matchEthType(Ethernet.TYPE_IPV6).matchIPv6Src(matchIp6SrcPrefix).matchIPv6Dst(matchIp6DstPrefix);
            if (matchIpv6FlowLabel) {
                selectorBuilder.matchIPv6FlowLabel(ipv6Packet.getFlowLabel());
            }
            if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_TCP) {
                TCP tcpPacket = (TCP) ipv6Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv6NextHeader).matchTcpSrc(TpPort.tpPort(tcpPacket.getSourcePort())).matchTcpDst(TpPort.tpPort(tcpPacket.getDestinationPort()));
            }
            if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_UDP) {
                UDP udpPacket = (UDP) ipv6Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv6NextHeader).matchUdpSrc(TpPort.tpPort(udpPacket.getSourcePort())).matchUdpDst(TpPort.tpPort(udpPacket.getDestinationPort()));
            }
            if (matchIcmpFields && ipv6NextHeader == IPv6.PROTOCOL_ICMP6) {
                ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv6NextHeader).matchIcmpv6Type(icmp6Packet.getIcmpType()).matchIcmpv6Code(icmp6Packet.getIcmpCode());
            }
        }
    }
    TrafficTreatment treatment;
    if (inheritFlowTreatment) {
        treatment = context.treatmentBuilder().setOutput(portNumber).build();
    } else {
        treatment = DefaultTrafficTreatment.builder().setOutput(portNumber).build();
    }
    ForwardingObjective forwardingObjective = DefaultForwardingObjective.builder().withSelector(selectorBuilder.build()).withTreatment(treatment).withPriority(flowPriority).withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).makeTemporary(flowTimeout).add();
    flowObjectiveService.forward(context.inPacket().receivedFrom().deviceId(), forwardingObjective);
    forwardPacket(macMetrics);
    // 
    if (packetOutOfppTable) {
        packetOut(context, PortNumber.TABLE, macMetrics);
    } else {
        packetOut(context, portNumber, macMetrics);
    }
}
Also used : TCP(org.onlab.packet.TCP) UDP(org.onlab.packet.UDP) IPv6(org.onlab.packet.IPv6) IPv4(org.onlab.packet.IPv4) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Ip6Prefix(org.onlab.packet.Ip6Prefix) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Ip4Prefix(org.onlab.packet.Ip4Prefix) ICMP6(org.onlab.packet.ICMP6) ICMP(org.onlab.packet.ICMP)

Aggregations

IPv6 (org.onlab.packet.IPv6)34 Ethernet (org.onlab.packet.Ethernet)28 UDP (org.onlab.packet.UDP)18 Test (org.junit.Test)17 DHCP6 (org.onlab.packet.DHCP6)17 ConnectPoint (org.onosproject.net.ConnectPoint)10 ICMP6 (org.onlab.packet.ICMP6)9 Interface (org.onosproject.net.intf.Interface)9 MacAddress (org.onlab.packet.MacAddress)8 OutboundPacket (org.onosproject.net.packet.OutboundPacket)8 Ip6Address (org.onlab.packet.Ip6Address)7 DeviceId (org.onosproject.net.DeviceId)7 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)7 InterfaceService (org.onosproject.net.intf.InterfaceService)7 ArrayList (java.util.ArrayList)6 VlanId (org.onlab.packet.VlanId)6 PacketContext (org.onosproject.net.packet.PacketContext)6 Logger (org.slf4j.Logger)6 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)5 ByteBuffer (java.nio.ByteBuffer)5