Search in sources :

Example 71 with IpAddress

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

the class Dhcp6HandlerImpl method timeTick.

/**
 * Find lease-expired ipaddresses and pd prefixes.
 * Removing host/route/fpm entries.
 */
public void timeTick() {
    long currentTime = System.currentTimeMillis();
    Collection<DhcpRecord> records = dhcpRelayStore.getDhcpRecords();
    log.debug("timeTick called currenttime {} records num {} ", currentTime, records.size());
    records.forEach(record -> {
        boolean addrOrPdRemoved = false;
        DHCP6.MsgType ip6Status = record.ip6Status().orElse(null);
        if (ip6Status == null) {
            log.debug("record is not valid v6 record.");
            return;
        }
        if ((currentTime - record.getLastIp6Update()) > ((record.addrPrefTime() + getDhcp6PollInterval() / 2) * 1000)) {
            // remove ipaddress from host/route table
            IpAddress ip = record.ip6Address().orElse(null);
            if (ip != null) {
                if (record.directlyConnected()) {
                    providerService.removeIpFromHost(HostId.hostId(record.macAddress(), record.vlanId()), ip);
                } else {
                    MacAddress gwMac = record.nextHop().orElse(null);
                    if (gwMac == null) {
                        log.warn("Can't find gateway mac address from record {} for ip6Addr", record);
                        return;
                    }
                    IpAddress nextHopIp = getFirstIpByHost(record.directlyConnected(), gwMac, record.vlanId());
                    Route route = new Route(Route.Source.DHCP, ip.toIpPrefix(), nextHopIp);
                    routeStore.removeRoute(route);
                }
                record.updateAddrPrefTime(0);
                record.ip6Address(null);
                addrOrPdRemoved = true;
                dhcpRelayStore.updateDhcpRecord(HostId.hostId(record.macAddress(), record.vlanId()), record);
                log.warn("IP6 address is set to null. delta {} lastUpdate {} addrPrefTime {}", (currentTime - record.getLastIp6Update()), record.getLastIp6Update(), record.addrPrefTime());
            }
        }
        if ((currentTime - record.getLastPdUpdate()) > ((record.pdPrefTime() + getDhcp6PollInterval() / 2) * 1000)) {
            // remove PD from route/fpm table
            IpPrefix pdIpPrefix = record.pdPrefix().orElse(null);
            if (pdIpPrefix != null) {
                if (record.directlyConnected()) {
                    providerService.removeIpFromHost(HostId.hostId(record.macAddress(), record.vlanId()), pdIpPrefix.address().getIp6Address());
                } else {
                    MacAddress gwMac = record.nextHop().orElse(null);
                    if (gwMac == null) {
                        log.warn("Can't find gateway mac address from record {} for PD prefix", record);
                        return;
                    }
                    IpAddress nextHopIp = getFirstIpByHost(record.directlyConnected(), gwMac, record.vlanId());
                    Route route = new Route(Route.Source.DHCP, pdIpPrefix, nextHopIp);
                    routeStore.removeRoute(route);
                    if (this.dhcpFpmEnabled) {
                        dhcpFpmPrefixStore.removeFpmRecord(pdIpPrefix);
                    }
                }
                record.updatePdPrefTime(0);
                record.pdPrefix(null);
                addrOrPdRemoved = true;
                dhcpRelayStore.updateDhcpRecord(HostId.hostId(record.macAddress(), record.vlanId()), record);
                log.warn("PD prefix is set to null.delta {} pdPrefTime {}", (currentTime - record.getLastPdUpdate()), record.pdPrefTime());
            }
        }
        if (addrOrPdRemoved && !record.ip6Address().isPresent() && !record.pdPrefix().isPresent()) {
            log.warn("ip6Status {} IP6 address and IP6 PD both are null. Remove record.", ip6Status);
            dhcpRelayStore.removeDhcpRecord(HostId.hostId(record.macAddress(), record.vlanId()));
        }
    });
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) MsgType(org.onlab.packet.DHCP6.MsgType) DHCP6(org.onlab.packet.DHCP6) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) Route(org.onosproject.routeservice.Route)

Example 72 with IpAddress

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

the class OpenstackTroubleshootManager method constructNorthSouthIcmpPacket.

/**
 * Constructs a north-south ICMP packet with the given destination IP/MAC.
 *
 * @param dstPort   destination instance port
 * @param icmpId    ICMP identifier
 * @param icmpSeq   ICMP sequence number
 * @return an ethernet frame which contains ICMP payload
 */
private Ethernet constructNorthSouthIcmpPacket(InstancePort dstPort, short icmpId, short icmpSeq) {
    IpAddress localIp = clusterService.getLocalNode().ip();
    IpAddress fip = instancePortService.floatingIp(dstPort.portId());
    if (fip != null) {
        return constructIcmpPacket(localIp, fip, LOCAL_MAC, dstPort.macAddress(), icmpId, icmpSeq);
    } else {
        return null;
    }
}
Also used : IpAddress(org.onlab.packet.IpAddress)

Example 73 with IpAddress

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

the class FpmAcceptRoutesCodec method decode.

@Override
public FpmPeerAcceptRoutes decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    IpAddress address = IpAddress.valueOf(json.path(PEER_ADDRESS).asText());
    int port = Integer.parseInt(json.path(PEER_PORT).asText());
    boolean isAcceptRoutes = Boolean.valueOf(json.path(ACCEPT_ROUTES).asText());
    FpmPeer peer = new FpmPeer(address, port);
    FpmPeerAcceptRoutes updatedPeer = new FpmPeerAcceptRoutes(peer, isAcceptRoutes);
    return updatedPeer;
}
Also used : FpmPeerAcceptRoutes(org.onosproject.routing.fpm.FpmPeerAcceptRoutes) IpAddress(org.onlab.packet.IpAddress) FpmPeer(org.onosproject.routing.fpm.FpmPeer)

Example 74 with IpAddress

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

the class FpmWebResource method getFpmConnectionsJsonOutput.

private ObjectNode getFpmConnectionsJsonOutput() {
    FpmInfoService fpmService = get(FpmInfoService.class);
    ObjectNode node = mapper().createObjectNode();
    ArrayNode connectionArray = mapper().createArrayNode();
    Map<FpmPeer, FpmPeerInfo> fpmPeers = fpmService.peers();
    fpmPeers.entrySet().stream().sorted(Comparator.<Map.Entry<FpmPeer, FpmPeerInfo>, IpAddress>comparing(e -> e.getKey().address()).thenComparing(e -> e.getKey().port())).map(Map.Entry::getValue).forEach(fpmPeerInfo -> connectionArray.add((new FpmCodec()).encode(fpmPeerInfo, this)));
    node.put("fpm-connections", connectionArray);
    return node;
}
Also used : FpmInfoService(org.onosproject.routing.fpm.FpmInfoService) FpmPeerInfo(org.onosproject.routing.fpm.FpmPeerInfo) PathParam(javax.ws.rs.PathParam) AbstractWebResource(org.onosproject.rest.AbstractWebResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FpmInfoService(org.onosproject.routing.fpm.FpmInfoService) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) Tools.nullIsIllegal(org.onlab.util.Tools.nullIsIllegal) IpAddress(org.onlab.packet.IpAddress) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) IOException(java.io.IOException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) FpmPeer(org.onosproject.routing.fpm.FpmPeer) List(java.util.List) Response(javax.ws.rs.core.Response) FpmPeerInfo(org.onosproject.routing.fpm.FpmPeerInfo) FpmPeerAcceptRoutes(org.onosproject.routing.fpm.FpmPeerAcceptRoutes) Tools.readTreeFromStream(org.onlab.util.Tools.readTreeFromStream) Comparator(java.util.Comparator) InputStream(java.io.InputStream) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) FpmPeer(org.onosproject.routing.fpm.FpmPeer) Map(java.util.Map)

Example 75 with IpAddress

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

the class InterfaceIpAddress method computeBroadcastAddress.

/**
 * Compute the IP broadcast address.
 *
 * @param ipAddress base IP address
 * @param subnetAddress subnet specification
 * @return the IP broadcast address
 */
public static IpAddress computeBroadcastAddress(IpAddress ipAddress, IpPrefix subnetAddress) {
    if (ipAddress.isIp6()) {
        return null;
    } else {
        IpAddress maskedIP = IpAddress.makeMaskedAddress(ipAddress, subnetAddress.prefixLength());
        int ipB = maskedIP.getIp4Address().toInt() | ((1 << (32 - subnetAddress.prefixLength())) - 1);
        return IpAddress.valueOf(ipB);
    }
}
Also used : IpAddress(org.onlab.packet.IpAddress)

Aggregations

IpAddress (org.onlab.packet.IpAddress)288 MacAddress (org.onlab.packet.MacAddress)63 VlanId (org.onlab.packet.VlanId)52 ConnectPoint (org.onosproject.net.ConnectPoint)48 Set (java.util.Set)46 DeviceId (org.onosproject.net.DeviceId)44 Logger (org.slf4j.Logger)40 Test (org.junit.Test)37 Collectors (java.util.stream.Collectors)36 Ethernet (org.onlab.packet.Ethernet)36 IpPrefix (org.onlab.packet.IpPrefix)36 HostId (org.onosproject.net.HostId)33 Host (org.onosproject.net.Host)32 Optional (java.util.Optional)30 HostLocation (org.onosproject.net.HostLocation)30 LoggerFactory (org.slf4j.LoggerFactory)30 ApplicationId (org.onosproject.core.ApplicationId)29 CoreService (org.onosproject.core.CoreService)29 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)29 JsonNode (com.fasterxml.jackson.databind.JsonNode)28