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

The following examples show how to use org.onlab.packet.IpAddress#equals() . 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: FloatingIpManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public boolean fixedIpIsUsed(IpAddress fixedIpAddr, TenantId tenantId,
                             FloatingIpId floatingIpId) {
    checkNotNull(fixedIpAddr, "Fixed IP address cannot be null");
    checkNotNull(tenantId, "Tenant Id cannot be null");
    checkNotNull(floatingIpId, "Floating IP Id cannot be null");
    Collection<FloatingIp> floatingIps = getFloatingIps();
    for (FloatingIp floatingIp : floatingIps) {
        IpAddress fixedIp = floatingIp.fixedIp();
        if (fixedIp != null) {
            if (fixedIp.equals(fixedIpAddr)
                    && floatingIp.tenantId().equals(tenantId)
                    && !floatingIp.id().equals(floatingIpId)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 2
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Set<Interface> getInterfacesByIp(IpAddress ip) {
    if (ip.equals(GW_IFACE_ADDR.ipAddress())) {
        return ImmutableSet.of(GW_IFACE);
    } else {
        return ImmutableSet.of();
    }
}
 
Example 3
Source File: VtnManager.java    From onos with Apache License 2.0 5 votes vote down vote up
private Subnet getSubnetOfFloatingIP(FloatingIp floatingIp) {
    DeviceId exVmPortId = DeviceId
            .deviceId(floatingIp.id().floatingIpId().toString());
    Collection<VirtualPort> exVmPortList = virtualPortService
            .getPorts(exVmPortId);
    VirtualPort exVmPort = null;
    if (exVmPortList != null) {
        exVmPort = exVmPortList.iterator().next();
    }
    if (exVmPort == null) {
        log.debug("exVM Port is null {}.", floatingIp);
        return null;
    }
    Set<FixedIp> fixedIps = exVmPort.fixedIps();
    SubnetId subnetId = null;
    for (FixedIp f : fixedIps) {
        IpAddress fp = f.ip();
        if (fp.equals(floatingIp.floatingIp())) {
            subnetId = f.subnetId();
            break;
        }
    }
    if (subnetId == null) {
        log.debug("subnetId is null {}.", floatingIp);
        return null;
    }
    Subnet subnet = subnetService.getSubnet(subnetId);
    return subnet;
}
 
Example 4
Source File: CastorArpManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the matching connect point corresponding to the peering IP address.
 *
 * @param target Target IP address
 * @return Connect point as a String
 */
private String getMatchingConnectPoint(IpAddress target) {
    Set<Peer> peers = castorStore.getAllPeers();
    for (Peer peer : peers) {
        IpAddress match = IpAddress.valueOf(peer.getIpAddress());
        if (match.equals(target)) {
            return peer.getPort();
        }
    }
    return null;
}
 
Example 5
Source File: BgpConfig.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Examines if BGP peer is connected.
 *
 * @param peer IP address of peer
 * @return result of search
 */
public boolean isConnectedToPeer(IpAddress peer) {
    for (final IpAddress entry : peers()) {
        if (entry.equals(peer)) {
            return true;
        }
    }
    return false;
}
 
Example 6
Source File: RoutingRulePopulator.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Removes a forwarding objective to punt all IP packets, destined to the
 * specified IP address, which should be router's port IP address.
 *
 * @param deviceId the switch dpid for the router
 * @param ipAddress the IP address of the router's port
 */
void revokeSingleIpPunts(DeviceId deviceId, IpAddress ipAddress) {
    TrafficSelector.Builder sbuilder = buildIpSelectorFromIpAddress(ipAddress);
    Optional<DeviceId> optDeviceId = Optional.of(deviceId);

    try {
        if (!ipAddress.equals(config.getRouterIpv4(deviceId)) &&
                !ipAddress.equals(config.getRouterIpv6(deviceId))) {
            srManager.packetService.cancelPackets(sbuilder.build(),
                                                  PacketPriority.CONTROL, srManager.appId, optDeviceId);
        }
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " Aborting revokeSingleIpPunts");
    }
}
 
Example 7
Source File: VtnManager.java    From onos with Apache License 2.0 4 votes vote down vote up
private void upStreamPacketProcessor(IPv4 ipPacket, DeviceId deviceId) {
    IpAddress srcIp = IpAddress.valueOf(ipPacket.getSourceAddress());
    IpAddress dstIp = IpAddress.valueOf(ipPacket.getDestinationAddress());
    FloatingIp floatingIp = null;
    Collection<FloatingIp> floatingIps = floatingIpService
            .getFloatingIps();
    Set<FloatingIp> floatingIpSet = Sets.newHashSet(floatingIps)
            .stream().collect(Collectors.toSet());
    for (FloatingIp f : floatingIpSet) {
        IpAddress fixIp = f.fixedIp();
        if (fixIp != null && fixIp.equals(srcIp)) {
            floatingIp = f;
            break;
        }
    }
    if (floatingIp == null) {
        return;
    }
    Subnet subnet = getSubnetOfFloatingIP(floatingIp);
    IpAddress gwIp = subnet.gatewayIp();
    Port exportPort = exPortOfDevice.get(deviceId);
    MacAddress exPortMac = MacAddress.valueOf(exportPort.annotations()
            .value(AnnotationKeys.PORT_MAC));
    IpPrefix ipPrefix = subnet.cidr();
    if (ipPrefix == null) {
        return;
    }
    int mask = ipPrefix.prefixLength();
    if (mask <= 0) {
        return;
    }
    Ethernet ethernet = null;
    // if the same ip segment
    if (IpUtil.checkSameSegment(floatingIp.floatingIp(), dstIp, mask)) {
        ethernet = buildArpRequest(dstIp, floatingIp.floatingIp(),
                                   exPortMac);
    } else {
        ethernet = buildArpRequest(gwIp, floatingIp.floatingIp(),
                                   exPortMac);
    }
    if (ethernet != null) {
        sendPacketOut(deviceId, exportPort.number(), ethernet);
    }
}
 
Example 8
Source File: VtnManager.java    From onos with Apache License 2.0 4 votes vote down vote up
private boolean downloadSnatRules(DeviceId deviceId, MacAddress srcMac,
                                  IpAddress srcIp, MacAddress dstMac,
                                  IpAddress dstIp, FloatingIp floatingIp) {
    TenantNetwork exNetwork = tenantNetworkService
            .getNetwork(floatingIp.networkId());
    IpAddress fixedIp = floatingIp.fixedIp();
    VirtualPortId vmPortId = floatingIp.portId();
    VirtualPort vmPort = virtualPortService.getPort(vmPortId);
    if (vmPort == null) {
        vmPort = VtnData.getPort(vPortStore, vmPortId);
    }
    Subnet subnet = getSubnetOfFloatingIP(floatingIp);
    IpPrefix ipPrefix = subnet.cidr();
    IpAddress gwIp = subnet.gatewayIp();
    if (ipPrefix == null) {
        return false;
    }
    int mask = ipPrefix.prefixLength();
    if (mask <= 0) {
        return false;
    }
    TenantRouter tenantRouter = TenantRouter
            .tenantRouter(floatingIp.tenantId(), floatingIp.routerId());
    SegmentationId l3vni = vtnRscService.getL3vni(tenantRouter);
    // if the same ip segment
    if (IpUtil.checkSameSegment(srcIp, dstIp, mask)) {
        snatService.programSnatSameSegmentRules(deviceId, l3vni, fixedIp,
                                                dstIp, dstMac, srcMac,
                                                srcIp,
                                                exNetwork.segmentationId(),
                                                Objective.Operation.ADD);
        if (dstIp.equals(gwIp)) {
            snatService
                    .programSnatDiffSegmentRules(deviceId, l3vni, fixedIp,
                                                 dstMac, srcMac, srcIp,
                                                 exNetwork.segmentationId(),
                                                 Objective.Operation.ADD);
        }
    }
    return true;
}
 
Example 9
Source File: PimInterface.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Process an incoming PIM Hello message.  There are a few things going on in
 * this method:
 * <ul>
 *     <li>We <em>may</em> have to create a new neighbor if one does not already exist</li>
 *     <li>We <em>may</em> need to re-elect a new DR if new information is received</li>
 *     <li>We <em>may</em> need to send an existing neighbor all joins if the genid changed</li>
 *     <li>We will refresh the neighbor's timestamp</li>
 * </ul>
 *
 * @param ethPkt the Ethernet packet header
 */
public void processHello(Ethernet ethPkt) {
    if (log.isTraceEnabled()) {
        log.trace("Received a PIM hello packet");
    }

    // We'll need to save our neighbors MAC address
    MacAddress nbrmac = ethPkt.getSourceMAC();

    // And we'll need to save neighbors IP Address.
    IPv4 iphdr = (IPv4) ethPkt.getPayload();
    IpAddress srcip = IpAddress.valueOf(iphdr.getSourceAddress());

    PIM pimhdr = (PIM) iphdr.getPayload();
    if (pimhdr.getPimMsgType() != PIM.TYPE_HELLO) {
        log.error("process Hello has received a non hello packet type: " + pimhdr.getPimMsgType());
        return;
    }

    // get the DR values for later calculation
    PimNeighbor dr = pimNeighbors.get(drIpaddress);
    checkNotNull(dr);

    IpAddress drip = drIpaddress;
    int drpri = dr.priority();

    // Assume we do not need to run a DR election
    boolean reElectDr = false;
    boolean genidChanged = false;

    PIMHello hello = (PIMHello) pimhdr.getPayload();

    // Determine if we already have a PIMNeighbor
    PimNeighbor nbr = pimNeighbors.getOrDefault(srcip, null);
    PimNeighbor newNbr = PimNeighbor.createPimNeighbor(srcip, nbrmac, hello.getOptions().values());

    if (nbr == null) {
        pimNeighbors.putIfAbsent(srcip, newNbr);
        nbr = newNbr;
    } else if (!nbr.equals(newNbr)) {
        if (newNbr.holdtime() == 0) {
            // Neighbor has shut down. Remove them and clean up
            pimNeighbors.remove(srcip, nbr);
            return;
        } else {
            // Neighbor has changed one of their options.
            pimNeighbors.put(srcip, newNbr);
            nbr = newNbr;
        }
    }

    // Refresh this neighbor's timestamp
    nbr.refreshTimestamp();

    /*
     * the election method will first determine if an election
     * needs to be run, if so it will run the election.  The
     * IP address of the DR will be returned.  If the IP address
     * of the DR is different from what we already have we know a
     * new DR has been elected.
     */
    IpAddress electedIp = election(nbr, drip, drpri);
    if (!drip.equals(electedIp)) {
        // we have a new DR.
        drIpaddress = electedIp;
    }
}