Java Code Examples for org.onlab.packet.IpAddress#isIp4()

The following examples show how to use org.onlab.packet.IpAddress#isIp4() . 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: HostLocationProvider.java    From onos with Apache License 2.0 6 votes vote down vote up
private void sendProbe(Host host, IpAddress targetIp) {
    Ethernet probePacket = null;
    if (targetIp.isIp4()) {
        // IPv4: Use ARP
        probePacket = buildArpRequest(targetIp, host);
    } else {
        // IPv6: Use Neighbor Discovery
        //TODO need to implement ndp probe
        log.info("Triggering probe on device {} ", host);
        return;
    }

    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(host.location().port()).build();

    OutboundPacket outboundPacket = new DefaultOutboundPacket(host.location().deviceId(), treatment,
            ByteBuffer.wrap(probePacket.serialize()));

    packetService.emit(outboundPacket);
}
 
Example 2
Source File: PcepClientImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public final void setChannel(Channel channel) {
    this.channel = channel;
    final SocketAddress address = channel.getRemoteAddress();
    if (address instanceof InetSocketAddress) {
        final InetSocketAddress inetAddress = (InetSocketAddress) address;
        final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress());
        if (ipAddress.isIp4()) {
            channelId = ipAddress.toString() + ':' + inetAddress.getPort();
        } else {
            channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort();
        }
    }
}
 
Example 3
Source File: BgpPeerImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public final void setChannel(Channel channel) {
    this.channel = channel;
    final SocketAddress address = channel.getRemoteAddress();
    if (address instanceof InetSocketAddress) {
        final InetSocketAddress inetAddress = (InetSocketAddress) address;
        final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress());
        if (ipAddress.isIp4()) {
            channelId = ipAddress.toString() + ':' + inetAddress.getPort();
        } else {
            channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort();
        }
    }
}
 
Example 4
Source File: McastUtils.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a filtering objective builder for multicast.
 *
 * @param ingressPort ingress port of the multicast stream
 * @param assignedVlan assigned VLAN ID
 * @param mcastIp the group address
 * @param routerMac router MAC. This is carried in metadata and used from some switches that
 *                  need to put unicast entry before multicast entry in TMAC table.
 * @param mcastRole the Multicast role
 * @param matchOnMac match or not on macaddress
 * @return filtering objective builder
 */
private FilteringObjective.Builder filterObjBuilder(PortNumber ingressPort, VlanId assignedVlan,
                                                    IpAddress mcastIp, MacAddress routerMac, McastRole mcastRole,
                                                    boolean matchOnMac) {
    FilteringObjective.Builder filtBuilder = DefaultFilteringObjective.builder();
    // Let's add the in port matching and the priority
    filtBuilder.withKey(Criteria.matchInPort(ingressPort))
            .withPriority(SegmentRoutingService.DEFAULT_PRIORITY);
    // According to the mcast role we match on the proper vlan
    // If the role is null we are on the transit or on the egress
    if (mcastRole == null) {
        filtBuilder.addCondition(Criteria.matchVlanId(egressVlan()));
    } else {
        filtBuilder.addCondition(Criteria.matchVlanId(ingressVlan()));
    }
    // Add vlan info to the treatment builder
    TrafficTreatment.Builder ttb = DefaultTrafficTreatment.builder()
            .pushVlan().setVlanId(assignedVlan);
    // Additionally match on mac address and augment the treatment
    if (matchOnMac) {
        // According to the IP type we set the proper match on the mac address
        if (mcastIp.isIp4()) {
            filtBuilder.addCondition(Criteria.matchEthDstMasked(MacAddress.IPV4_MULTICAST,
                    MacAddress.IPV4_MULTICAST_MASK));
        } else {
            filtBuilder.addCondition(Criteria.matchEthDstMasked(MacAddress.IPV6_MULTICAST,
                    MacAddress.IPV6_MULTICAST_MASK));
        }
        // We set mac address to the treatment
        if (routerMac != null && !routerMac.equals(MacAddress.NONE)) {
            ttb.setEthDst(routerMac);
        }
    }
    // We finally build the meta treatment
    TrafficTreatment tt = ttb.build();
    filtBuilder.withMeta(tt);
    // Done, we return a permit filtering objective
    return filtBuilder.permit().fromApp(srManager.appId());
}
 
Example 5
Source File: OFChannelHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx)
        throws Exception {

    channel = ctx.channel();
    log.info("New switch connection from {}",
             channel.remoteAddress());

    SocketAddress address = channel.remoteAddress();
    if (address instanceof InetSocketAddress) {
        final InetSocketAddress inetAddress = (InetSocketAddress) address;
        final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress());
        if (ipAddress.isIp4()) {
            channelId = ipAddress.toString() + ':' + inetAddress.getPort();
        } else {
            channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort();
        }
    } else {
        channelId = channel.toString();
    }

    dispatcher = Executors.newSingleThreadExecutor(groupedThreads("onos/of/dispatcher", channelId, log));

    /*
        hack to wait for the switch to tell us what it's
        max version is. This is not spec compliant and should
        be removed as soon as switches behave better.
     */
    //sendHandshakeHelloMessage();
    setState(ChannelState.WAIT_HELLO);
}
 
Example 6
Source File: DefaultHostProbingProvider.java    From onos with Apache License 2.0 5 votes vote down vote up
private void probeHostInternal(Host host, ConnectPoint connectPoint, ProbeMode probeMode,
                               MacAddress probeMac, int retry) {
    if (!mastershipService.isLocalMaster(connectPoint.deviceId())) {
        log.debug("Current node is not master of {}, abort probing {}", connectPoint.deviceId(), host);
        return;
    }

    log.debug("probeHostInternal host={}, cp={}, mode={}, probeMac={}, retry={}", host, connectPoint,
            probeMode, probeMac, retry);
    Optional<IpAddress> ipOptional = host.ipAddresses().stream().findFirst();

    if (ipOptional.isPresent()) {
        probeMac = hostProbingProviderService.addProbingHost(host, connectPoint, probeMode, probeMac, retry);

        IpAddress ip = ipOptional.get();
        log.debug("Constructing {} probe for host {} with {}", probeMode, host.id(), ip);
        Ethernet probe;
        if (ip.isIp4()) {
            probe = ARP.buildArpRequest(probeMac.toBytes(), Ip4Address.ZERO.toOctets(),
                    host.id().mac().toBytes(), ip.toOctets(),
                    host.id().mac().toBytes(), host.id().vlanId().toShort());
        } else {
            probe = NeighborSolicitation.buildNdpSolicit(
                    ip.getIp6Address(),
                    Ip6Address.valueOf(IPv6.getLinkLocalAddress(probeMac.toBytes())),
                    ip.getIp6Address(),
                    probeMac,
                    host.id().mac(),
                    host.id().vlanId());
        }

        // NOTE: delay the probe a little bit to wait for the store synchronization is done
        hostProber.schedule(() ->
                sendLocationProbe(probe, connectPoint), PROBE_INIT_DELAY_MS, TimeUnit.MILLISECONDS);
    } else {
        log.debug("Host {} has no IP address yet. Skip probing.", host);
    }
}
 
Example 7
Source File: SimpleFabricManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean requestMac(IpAddress ip) {
    FabricSubnet fabricSubnet = fabricSubnet(ip);
    if (fabricSubnet == null) {
        log.warn("simple fabric request mac failed for unknown fabricSubnet: {}", ip);
        return false;
    }
    FabricNetwork fabricNetwork = fabricNetwork(fabricSubnet.networkName());
    if (fabricNetwork == null) {
        log.warn("simple fabric request mac failed for unknown fabricNetwork name {}: {}",
                 fabricSubnet.networkName(), ip);
        return false;
    }
    log.debug("simple fabric send request mac fabricNetwork {}: {}", fabricNetwork.name(), ip);
    for (Interface iface : fabricNetwork.interfaces()) {
        Ethernet neighbourReq;
        if (ip.isIp4()) {
            neighbourReq = ARP.buildArpRequest(fabricSubnet.gatewayMac().toBytes(),
                                               fabricSubnet.gatewayIp().toOctets(),
                                               ip.toOctets(),
                                               iface.vlan().toShort());
        } else {
            byte[] soliciteIp = IPv6.getSolicitNodeAddress(ip.toOctets());
            neighbourReq = NeighborSolicitation.buildNdpSolicit(
                                               ip.getIp6Address(),
                                               fabricSubnet.gatewayIp().getIp6Address(),
                                               Ip6Address.valueOf(soliciteIp),
                                               MacAddress.valueOf(fabricSubnet.gatewayMac().toBytes()),
                                               MacAddress.valueOf(IPv6.getMCastMacAddress(soliciteIp)),
                                               iface.vlan());
        }
        TrafficTreatment treatment = DefaultTrafficTreatment.builder()
                                           .setOutput(iface.connectPoint().port()).build();
        OutboundPacket packet = new DefaultOutboundPacket(iface.connectPoint().deviceId(),
                                           treatment, ByteBuffer.wrap(neighbourReq.serialize()));
        packetService.emit(packet);
    }
    return true;
}
 
Example 8
Source File: PeerConnectivityManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a traffic selector based on the set of input parameters.
 *
 * @param ipProto IP protocol
 * @param srcIp source IP address
 * @param dstIp destination IP address
 * @param srcTcpPort source TCP port, or null if shouldn't be set
 * @param dstTcpPort destination TCP port, or null if shouldn't be set
 * @return the new traffic selector
 */
private TrafficSelector buildSelector(byte ipProto, VlanId ingressVlanId,
                                      IpAddress srcIp,
                                      IpAddress dstIp, Short srcTcpPort,
                                      Short dstTcpPort) {
    TrafficSelector.Builder builder = DefaultTrafficSelector.builder().matchIPProtocol(ipProto);

    // Match on VLAN Id if a VLAN Id configured on the ingress interface
    if (!ingressVlanId.equals(VlanId.NONE)) {
        builder.matchVlanId(ingressVlanId);
    }

    if (dstIp.isIp4()) {
        builder.matchEthType(Ethernet.TYPE_IPV4)
               .matchIPSrc(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET_MASK_LENGTH))
               .matchIPDst(IpPrefix.valueOf(dstIp, IpPrefix.MAX_INET_MASK_LENGTH));
    } else {
        builder.matchEthType(Ethernet.TYPE_IPV6)
               .matchIPv6Src(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET6_MASK_LENGTH))
               .matchIPv6Dst(IpPrefix.valueOf(dstIp, IpPrefix.MAX_INET6_MASK_LENGTH));
    }

    if (srcTcpPort != null) {
        builder.matchTcpSrc(TpPort.tpPort(srcTcpPort));
    }

    if (dstTcpPort != null) {
        builder.matchTcpDst(TpPort.tpPort(dstTcpPort));
    }

    return builder.build();
}
 
Example 9
Source File: DeviceConfiguration.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Gets router ip address based on the destination ip address.
 *
 * @param destIpAddress the destination ip address
 * @param routerDeviceId the device id
 * @return the ip address of the routes
 */
public IpAddress getRouterIpAddress(IpAddress destIpAddress, DeviceId routerDeviceId) {
    IpAddress routerIpAddress;
    try {
        routerIpAddress = destIpAddress.isIp4() ? getRouterIpv4(routerDeviceId) :
                getRouterIpv6(routerDeviceId);
    } catch (DeviceConfigNotFoundException e) {
        routerIpAddress = null;
    }
    return routerIpAddress;
}
 
Example 10
Source File: SimpleFabricManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public FabricSubnet fabricSubnet(IpAddress ip) {
    if (ip.isIp4()) {
        return ip4SubnetTable.getValueForLongestKeyPrefixing(
                 createBinaryString(IpPrefix.valueOf(ip, Ip4Address.BIT_LENGTH)));
    } else {
        return ip6SubnetTable.getValueForLongestKeyPrefixing(
                 createBinaryString(IpPrefix.valueOf(ip, Ip6Address.BIT_LENGTH)));
    }
}
 
Example 11
Source File: ReactiveRoutingConfiguration.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isIpAddressLocal(IpAddress ipAddress) {
    if (ipAddress.isIp4()) {
        return localPrefixTable4.getValuesForKeysPrefixing(
                createBinaryString(
                IpPrefix.valueOf(ipAddress, Ip4Address.BIT_LENGTH)))
                .iterator().hasNext();
    } else {
        return localPrefixTable6.getValuesForKeysPrefixing(
                createBinaryString(
                IpPrefix.valueOf(ipAddress, Ip6Address.BIT_LENGTH)))
                .iterator().hasNext();
    }
}
 
Example 12
Source File: Ovs.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Builds Open-flow device id with ip address, and index.
 *
 * @param addr  ip address
 * @param index index
 * @return created device id
 */
public static DeviceId buildOfDeviceId(IpAddress addr, int index) {
    if (addr.isIp4()) {
        Ip4Address v4Addr = addr.getIp4Address();
        return DeviceId.deviceId(String.format(OPENFLOW_DEVID_FORMAT, v4Addr.toInt(), index));
    } else if (addr.isIp6()) {
        Ip6Address v6Addr = addr.getIp6Address();
        return DeviceId.deviceId(String.format(OPENFLOW_DEVID_FORMAT, v6Addr.hashCode(), index));
    } else {
        return DeviceId.deviceId(String.format(OPENFLOW_DEVID_FORMAT, addr.hashCode(), index));
    }
}
 
Example 13
Source File: RoutingRulePopulator.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a Forwarding Objective builder for the MPLS rule that references
 * the desired Next Objective. Creates a DestinationSet that allows the
 * groupHandler to create or find the required next objective.
 *
 * @param targetSw the target sw
 * @param nextHops the set of next hops
 * @param phpRequired true if penultimate-hop-popping is required
 * @param isBos true if matched label is bottom-of-stack
 * @param meta metadata for creating next objective
 * @param routerIp the router ip representing the destination switch
 * @param destSw the destination sw
 * @return the mpls forwarding objective builder
 */
private ForwardingObjective.Builder getMplsForwardingObjective(
                                         DeviceId targetSw,
                                         Set<DeviceId> nextHops,
                                         boolean phpRequired,
                                         boolean isBos,
                                         TrafficSelector meta,
                                         IpAddress routerIp,
                                         int segmentId,
                                         DeviceId destSw) {

    ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective
            .builder().withFlag(ForwardingObjective.Flag.SPECIFIC);

    TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
    DestinationSet ds = null;
    DestinationSet.DestinationSetType dstType = null;
    boolean simple = false;
    if (phpRequired) {
        // php case - pop should always be flow-action
        log.debug("getMplsForwardingObjective: php required");
        tbuilder.deferred().copyTtlIn();
        if (isBos) {
            if (routerIp.isIp4()) {
                tbuilder.deferred().popMpls(EthType.EtherType.IPV4.ethType());
            } else {
                tbuilder.deferred().popMpls(EthType.EtherType.IPV6.ethType());
            }
            tbuilder.decNwTtl();
            // standard case -> BoS == True; pop results in IP packet and forwarding
            // is via an ECMP group
            ds = DestinationSet.createTypePopBos(destSw);
        } else {
            tbuilder.deferred().popMpls(EthType.EtherType.MPLS_UNICAST.ethType())
                .decMplsTtl();
            // double-label case -> BoS == False, pop results in MPLS packet
            // depending on configuration we can ECMP this packet or choose one output
            ds = DestinationSet.createTypePopNotBos(destSw);
            if (!srManager.getMplsEcmp()) {
               simple = true;
            }
        }
    } else {
        // swap with self case - SR CONTINUE
        log.debug("getMplsForwardingObjective: swap with self");
        tbuilder.deferred().decMplsTtl();
        // swap results in MPLS packet with same BoS bit regardless of bit value
        // depending on configuration we can ECMP this packet or choose one output
        // differentiate here between swap with not bos or swap with bos
        ds = isBos ? DestinationSet.createTypeSwapBos(segmentId, destSw) :
                DestinationSet.createTypeSwapNotBos(segmentId, destSw);
        if (!srManager.getMplsEcmp()) {
            simple = true;
        }
    }

    fwdBuilder.withTreatment(tbuilder.build());
    log.debug("Trying to get a nextObjId for mpls rule on device:{} to ds:{}",
              targetSw, ds);
    DefaultGroupHandler gh = srManager.getGroupHandler(targetSw);
    if (gh == null) {
        log.warn("getNextObjectiveId query - groupHandler for device {} "
                + "not found", targetSw);
        return null;
    }

    Map<DeviceId, Set<DeviceId>> dstNextHops = new HashMap<>();
    dstNextHops.put(destSw, nextHops);
    int nextId = gh.getNextObjectiveId(ds, dstNextHops, meta, simple);
    if (nextId <= 0) {
        log.warn("No next objective in {} for ds: {}", targetSw, ds);
        return null;
    } else {
        log.debug("nextObjId found:{} for mpls rule on device:{} to ds:{}",
                  nextId, targetSw, ds);
    }

    fwdBuilder.nextStep(nextId);
    return fwdBuilder;
}
 
Example 14
Source File: ReactiveRoutingFib.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Generates MultiPointToSinglePointIntent for both source host and
 * destination host located in local SDN network.
 *
 * @param dstIpAddress the destination IP address
 * @param dstConnectPoint the destination host connect point
 * @param dstMacAddress the MAC address of destination host
 * @param srcConnectPoint the connect point where packet-in from
 * @return the generated MultiPointToSinglePointIntent
 */
private MultiPointToSinglePointIntent hostToHostIntentGenerator(
        IpAddress dstIpAddress,
        ConnectPoint dstConnectPoint,
        MacAddress dstMacAddress,
        ConnectPoint srcConnectPoint) {
    checkNotNull(dstIpAddress);
    checkNotNull(dstConnectPoint);
    checkNotNull(dstMacAddress);
    checkNotNull(srcConnectPoint);

    Set<FilteredConnectPoint> ingressPoints = new HashSet<>();
    ingressPoints.add(new FilteredConnectPoint(srcConnectPoint));
    IpPrefix dstIpPrefix = dstIpAddress.toIpPrefix();

    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    if (dstIpAddress.isIp4()) {
        selector.matchEthType(Ethernet.TYPE_IPV4);
        selector.matchIPDst(dstIpPrefix);
    } else {
        selector.matchEthType(Ethernet.TYPE_IPV6);
        selector.matchIPv6Dst(dstIpPrefix);
    }

    // Rewrite the destination MAC address
    TrafficTreatment.Builder treatment =
            DefaultTrafficTreatment.builder().setEthDst(dstMacAddress);

    Key key = Key.of(dstIpPrefix.toString(), appId);
    int priority = dstIpPrefix.prefixLength() * PRIORITY_MULTIPLIER
            + PRIORITY_OFFSET;
    MultiPointToSinglePointIntent intent =
            MultiPointToSinglePointIntent.builder()
                    .appId(appId)
                    .key(key)
                    .selector(selector.build())
                    .treatment(treatment.build())
                    .filteredIngressPoints(ingressPoints)
                    .filteredEgressPoint(new FilteredConnectPoint(dstConnectPoint))
                    .priority(priority)
                    .constraints(CONSTRAINTS)
                    .build();

    log.trace("Generates ConnectivityHostToHost = {} ", intent);
    return intent;
}
 
Example 15
Source File: SdnIpReactiveRouting.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Routes packet reactively.
 *
 * @param dstIpAddress the destination IP address of a packet
 * @param srcIpAddress the source IP address of a packet
 * @param srcConnectPoint the connect point where a packet comes from
 * @param srcMacAddress the source MAC address of a packet
 */
private void packetReactiveProcessor(IpAddress dstIpAddress,
                                    IpAddress srcIpAddress,
                                    ConnectPoint srcConnectPoint,
                                    MacAddress srcMacAddress) {
    checkNotNull(dstIpAddress);
    checkNotNull(srcIpAddress);
    checkNotNull(srcConnectPoint);
    checkNotNull(srcMacAddress);

    //
    // Step1: Try to update the existing intent first if it exists.
    //
    IpPrefix ipPrefix = null;
    Route route = null;
    if (config.isIpAddressLocal(dstIpAddress)) {
        if (dstIpAddress.isIp4()) {
            ipPrefix = IpPrefix.valueOf(dstIpAddress,
                    Ip4Address.BIT_LENGTH);
        } else {
            ipPrefix = IpPrefix.valueOf(dstIpAddress,
                    Ip6Address.BIT_LENGTH);
        }
    } else {
        // Get IP prefix from BGP route table
        route = routeService.longestPrefixMatch(dstIpAddress);
        if (route != null) {
            ipPrefix = route.prefix();
        }
    }
    if (ipPrefix != null
            && intentRequestListener.mp2pIntentExists(ipPrefix)) {
        intentRequestListener.updateExistingMp2pIntent(ipPrefix,
                srcConnectPoint);
        return;
    }

    //
    // Step2: There is no existing intent for the destination IP address.
    // Check whether it is necessary to create a new one. If necessary then
    // create a new one.
    //
    TrafficType trafficType =
            trafficTypeClassifier(srcConnectPoint, dstIpAddress);

    switch (trafficType) {
    case HOST_TO_INTERNET:
        // If the destination IP address is outside the local SDN network.
        // The Step 1 has already handled it. We do not need to do anything here.
        if (route != null) {
            intentRequestListener.setUpConnectivityHostToInternet(srcIpAddress,
                    ipPrefix, route.nextHop());
        }
        break;
    case INTERNET_TO_HOST:
        intentRequestListener.setUpConnectivityInternetToHost(dstIpAddress);
        break;
    case HOST_TO_HOST:
        intentRequestListener.setUpConnectivityHostToHost(dstIpAddress,
                srcIpAddress, srcMacAddress, srcConnectPoint);
        break;
    case INTERNET_TO_INTERNET:
        log.trace("This is transit traffic, "
                + "the intent should be preinstalled already");
        break;
    case DROP:
        // TODO here should setUpDropPacketIntent(...);
        // We need a new type of intent here.
        break;
    case UNKNOWN:
        log.trace("This is unknown traffic, so we do nothing");
        break;
    default:
        break;
    }
}
 
Example 16
Source File: McastHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Establishes a path from source to sink for given multicast group.
 *
 * @param source connect point of the multicast source
 * @param sink connection point of the multicast sink
 * @param mcastIp multicast group IP address
 */
private void processSinkAddedInternal(ConnectPoint source, ConnectPoint sink,
                                      IpAddress mcastIp, List<Path> allPaths) {
    lastMcastChange.set(Instant.now());
    log.info("Processing sink added {} for group {} and for source {}", sink, mcastIp, source);
    // Process the ingress device
    McastFilteringObjStoreKey mcastFilterObjStoreKey = new McastFilteringObjStoreKey(source,
                                                       mcastUtils.assignedVlan(source), mcastIp.isIp4());
    addFilterToDevice(mcastFilterObjStoreKey, mcastIp, INGRESS);
    if (source.deviceId().equals(sink.deviceId())) {
        if (source.port().equals(sink.port())) {
            log.warn("Skip {} since sink {} is on the same port of source {}. Abort",
                     mcastIp, sink, source);
            return;
        }
        addPortToDevice(sink.deviceId(), sink.port(), mcastIp, mcastUtils.assignedVlan(source));
        mcastRoleStore.put(new McastRoleStoreKey(mcastIp, sink.deviceId(), source), INGRESS);
        return;
    }
    // Find a path. If present, create/update groups and flows for each hop
    Optional<Path> mcastPath = getPath(source.deviceId(), sink.deviceId(), mcastIp, allPaths);
    if (mcastPath.isPresent()) {
        List<Link> links = mcastPath.get().links();
        McastPathStoreKey pathStoreKey = new McastPathStoreKey(mcastIp, source);
        // Setup mcast role for ingress
        mcastRoleStore.put(new McastRoleStoreKey(mcastIp, source.deviceId(), source), INGRESS);
        // Setup properly the transit forwarding
        links.forEach(link -> {
            addPortToDevice(link.src().deviceId(), link.src().port(), mcastIp,
                            mcastUtils.assignedVlan(link.src().deviceId()
                                                            .equals(source.deviceId()) ? source : null));
            McastFilteringObjStoreKey filteringKey = new McastFilteringObjStoreKey(link.dst(),
                                                               mcastUtils.assignedVlan(null), mcastIp.isIp4());
            addFilterToDevice(filteringKey, mcastIp, null);
        });
        // Setup mcast role for the transit
        links.stream()
                .filter(link -> !link.dst().deviceId().equals(sink.deviceId()))
                .forEach(link -> mcastRoleStore.put(new McastRoleStoreKey(mcastIp, link.dst().deviceId(),
                                                                          source), TRANSIT));
        // Process the egress device
        addPortToDevice(sink.deviceId(), sink.port(), mcastIp, mcastUtils.assignedVlan(null));
        // Setup mcast role for egress
        mcastRoleStore.put(new McastRoleStoreKey(mcastIp, sink.deviceId(), source), EGRESS);
        // Store the used path
        mcastPathStore.put(pathStoreKey, links);
    } else {
        log.warn("Unable to find a path from {} to {}. Abort sinkAdded", source.deviceId(), sink.deviceId());
    }
}
 
Example 17
Source File: DistributedEvpnRouteStore.java    From onos with Apache License 2.0 4 votes vote down vote up
private EvpnTable getDefaultRouteTable(IpAddress ip) {
    EvpnRouteTableId routeTableId = (ip.isIp4()) ? EVPN_IPV4 : EVPN_IPV6;
    return routeTables.getOrDefault(routeTableId, EmptyEvpnRouteTable
            .instance());
}
 
Example 18
Source File: LocalRouteStore.java    From onos with Apache License 2.0 4 votes vote down vote up
private RouteTable getDefaultRouteTable(IpAddress ip) {
    RouteTableId routeTableId = (ip.isIp4()) ? IPV4 : IPV6;
    return routeTables.get(routeTableId);
}
 
Example 19
Source File: DefaultResolvedRouteStore.java    From onos with Apache License 2.0 4 votes vote down vote up
private RouteTable getDefaultRouteTable(IpAddress ip) {
    RouteTableId routeTableId = (ip.isIp4()) ? IPV4 : IPV6;
    return routeTables.get(routeTableId);
}
 
Example 20
Source File: LispMapServer.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Handles info-request message and replies with info-reply message.
 *
 * @param message info-request message
 * @return info-reply message
 */
LispInfoReply processInfoRequest(LispMessage message) {
    LispInfoRequest request = (LispInfoRequest) message;

    if (!checkInfoRequestAuthData(request)) {
        log.warn(INVALID_AUTHENTICATION_DATA_MSG, "Info-Request");
        return null;
    }

    NatAddressBuilder natBuilder = new NatAddressBuilder();
    try {
        LispAfiAddress msAddress =
                    new LispIpv4Address(valueOf(InetAddress.getLocalHost()));
        natBuilder.withMsRlocAddress(msAddress);
        natBuilder.withMsUdpPortNumber((short) INFO_REPLY_PORT);

        // try to extract global ETR RLOC address from info-request
        IpAddress globalRlocIp = valueOf(request.getSender().getAddress());
        LispAfiAddress globalRlocAddress;
        if (globalRlocIp.isIp4()) {
            globalRlocAddress = new LispIpv4Address(globalRlocIp);
        } else {
            globalRlocAddress = new LispIpv6Address(globalRlocIp);
        }
        natBuilder.withGlobalEtrRlocAddress(globalRlocAddress);
        natBuilder.withEtrUdpPortNumber((short) request.getSender().getPort());
        natBuilder.withPrivateEtrRlocAddress(new LispNoAddress());

        // TODO: need to specify RTR addresses

    } catch (UnknownHostException e) {
        log.warn(FAILED_TO_FORMULATE_NAT_MSG, e);
    }

    InfoReplyBuilder replyBuilder = new DefaultInfoReplyBuilder();
    replyBuilder.withKeyId(request.getKeyId());
    replyBuilder.withAuthDataLength(valueOf(authConfig.lispAuthKeyId()).getHashLength());
    replyBuilder.withAuthKey(authConfig.lispAuthKey());
    replyBuilder.withNonce(request.getNonce());
    replyBuilder.withEidPrefix(request.getPrefix());
    replyBuilder.withMaskLength(request.getMaskLength());
    replyBuilder.withTtl(request.getTtl());
    replyBuilder.withNatLcafAddress(natBuilder.build());
    replyBuilder.withIsInfoReply(true);

    LispInfoReply reply = replyBuilder.build();
    reply.configSender(request.getSender());

    return reply;
}