Search in sources :

Example 41 with IpAddress

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

the class BgpConfigTest method createInitialSpeaker.

private BgpConfig.BgpSpeakerConfig createInitialSpeaker() {
    Optional<String> speakerName = Optional.of("bgp1");
    ConnectPoint connectPoint = CONNECT_POINT1;
    Set<IpAddress> connectedPeers = new HashSet<>(Arrays.asList(IP1, IP2, IP3));
    return new BgpConfig.BgpSpeakerConfig(speakerName, NO_VLAN, connectPoint, connectedPeers);
}
Also used : IpAddress(org.onlab.packet.IpAddress) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet)

Example 42 with IpAddress

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

the class K8sIpAddressListCommand method doExecute.

@Override
protected void doExecute() {
    K8sIpamService ipamService = get(K8sIpamService.class);
    K8sNetworkService networkService = get(K8sNetworkService.class);
    if (networkIds == null || networkIds.length == 0) {
        networkIds = networkService.networks().stream().map(K8sNetwork::networkId).toArray(String[]::new);
    }
    Map<String, Map<IpAddress, MacAddress>> ipMacs = Maps.newConcurrentMap();
    if (available && reserved) {
        error("Only one of list options (available | reserved) can be specified.");
        return;
    }
    if (!(available || reserved)) {
        error("At least one of list options (available | reserved) should be specified.");
        return;
    }
    for (String networkId : networkIds) {
        Map<IpAddress, MacAddress> tmpIpMacs = Maps.newConcurrentMap();
        if (available) {
            ipamService.availableIps(networkId).forEach(n -> tmpIpMacs.put(n, ZERO));
        }
        if (reserved) {
            Set<K8sPort> ports = networkService.ports(networkId);
            ipamService.allocatedIps(networkId).forEach(ip -> {
                MacAddress mac = ports.stream().filter(p -> p.ipAddress().equals(ip)).map(K8sPort::macAddress).findAny().orElse(ZERO);
                tmpIpMacs.put(ip, mac);
            });
        }
        ipMacs.put(networkId, tmpIpMacs);
    }
    if (ipMacs.size() > 0) {
        print(FORMAT, "Network ID", "IP Address", "MAC Address");
        ipMacs.forEach((k, v) -> v.forEach((ip, mac) -> print(FORMAT, k, ip, mac)));
    } else {
        print("No IP addresses are available or reserved.");
    }
}
Also used : K8sIpamService(org.onosproject.k8snetworking.api.K8sIpamService) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) K8sNetworkService(org.onosproject.k8snetworking.api.K8sNetworkService) Maps(com.google.common.collect.Maps) Command(org.apache.karaf.shell.api.action.Command) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) ZERO(org.onlab.packet.MacAddress.ZERO) K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) Map(java.util.Map) K8sPort(org.onosproject.k8snetworking.api.K8sPort) MacAddress(org.onlab.packet.MacAddress) Option(org.apache.karaf.shell.api.action.Option) IpAddress(org.onlab.packet.IpAddress) K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) K8sNetworkService(org.onosproject.k8snetworking.api.K8sNetworkService) IpAddress(org.onlab.packet.IpAddress) K8sPort(org.onosproject.k8snetworking.api.K8sPort) MacAddress(org.onlab.packet.MacAddress) Map(java.util.Map) K8sIpamService(org.onosproject.k8snetworking.api.K8sIpamService)

Example 43 with IpAddress

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

the class PimInterface method processHello.

/**
 * 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;
    }
}
Also used : PIM(org.onlab.packet.PIM) IPv4(org.onlab.packet.IPv4) IpAddress(org.onlab.packet.IpAddress) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) MacAddress(org.onlab.packet.MacAddress) PIMHello(org.onlab.packet.pim.PIMHello)

Example 44 with IpAddress

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

the class PimPacketHandler method processPacket.

/**
 * Sanitize and process the packet.
 * TODO: replace ConnectPoint with PIMInterface when PIMInterface has been added.
 *
 * @param ethPkt the packet starting with the Ethernet header.
 * @param pimi the PIM Interface the packet arrived on.
 */
public void processPacket(Ethernet ethPkt, PimInterface pimi) {
    checkNotNull(ethPkt);
    checkNotNull(pimi);
    // Sanitize the ethernet header to ensure it is IPv4.  IPv6 we'll deal with later
    if (ethPkt.getEtherType() != Ethernet.TYPE_IPV4) {
        return;
    }
    // Get the IP header
    IPv4 ip = (IPv4) ethPkt.getPayload();
    if (ip.getProtocol() != IPv4.PROTOCOL_PIM) {
        return;
    }
    // Get the address of our the neighbor that sent this packet to us.
    IpAddress nbraddr = IpAddress.valueOf(ip.getDestinationAddress());
    if (log.isTraceEnabled()) {
        log.trace("Packet {} received on port {}", nbraddr, pimi);
    }
    // Get the PIM header
    PIM pim = (PIM) ip.getPayload();
    checkNotNull(pim);
    // Process the pim packet
    switch(pim.getPimMsgType()) {
        case PIM.TYPE_HELLO:
            pimi.processHello(ethPkt);
            break;
        case PIM.TYPE_JOIN_PRUNE_REQUEST:
            pimi.processJoinPrune(ethPkt);
            log.debug("Received a PIM Join/Prune message");
            break;
        default:
            log.debug("Received unsupported PIM type: {}", pim.getPimMsgType());
            break;
    }
}
Also used : PIM(org.onlab.packet.PIM) IPv4(org.onlab.packet.IPv4) IpAddress(org.onlab.packet.IpAddress)

Example 45 with IpAddress

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

the class SummaryCommand method doExecute.

@Override
protected void doExecute() {
    IpAddress nodeIp = get(ClusterService.class).getLocalNode().ip();
    Version version = get(CoreService.class).version();
    long numNodes = activeNodes(get(ClusterService.class).getNodes());
    int numDevices = get(DeviceService.class).getDeviceCount();
    int numLinks = get(LinkService.class).getLinkCount();
    int numHosts = get(HostService.class).getHostCount();
    int numScc = get(TopologyService.class).currentTopology().clusterCount();
    int numFlows = get(FlowRuleService.class).getFlowRuleCount();
    long numIntents = get(IntentService.class).getIntentCount();
    String clusterId = get(ClusterMetadataService.class).getClusterMetadata().getName();
    if (outputJson()) {
        print("%s", new ObjectMapper().createObjectNode().put("node", nodeIp.toString()).put("version", version.toString()).put("clusterId", clusterId).put("nodes", numNodes).put("devices", numDevices).put("links", numLinks).put("hosts", numHosts).put("SCC(s)", numScc).put("flows", numFlows).put("intents", numIntents));
    } else {
        print("node=%s, version=%s clusterId=%s", nodeIp, version, clusterId);
        print("nodes=%d, devices=%d, links=%d, hosts=%d, SCC(s)=%s, flows=%d, intents=%d", numNodes, numDevices, numLinks, numHosts, numScc, numFlows, numIntents);
    }
}
Also used : HostService(org.onosproject.net.host.HostService) IntentService(org.onosproject.net.intent.IntentService) Version(org.onosproject.core.Version) DeviceService(org.onosproject.net.device.DeviceService) CoreService(org.onosproject.core.CoreService) IpAddress(org.onlab.packet.IpAddress) FlowRuleService(org.onosproject.net.flow.FlowRuleService) LinkService(org.onosproject.net.link.LinkService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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