Search in sources :

Example 26 with IpAddress

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

the class HostEventConverter method buildHostProtoMessage.

private HostNotificationProto buildHostProtoMessage(HostEvent hostEvent) {
    HostNotificationProto.Builder notificationBuilder = HostNotificationProto.newBuilder();
    HostProto hostCore = HostProto.newBuilder().setHostId(HostIdProtoTranslator.translate(hostEvent.subject().id())).setConfigured(hostEvent.subject().configured()).addAllIpAddresses(hostEvent.subject().ipAddresses().stream().map(IpAddress::toString).collect(Collectors.toList())).setLocation(HostLocationProtoTranslator.translate(hostEvent.subject().location())).setVlan(hostEvent.subject().vlan().toShort()).putAllAnnotations(AnnotationsTranslator.asMap(hostEvent.subject().annotations())).build();
    notificationBuilder.setHostEventType(getProtoType(hostEvent)).setHost(hostCore);
    return notificationBuilder.build();
}
Also used : HostNotificationProto(org.onosproject.grpc.net.host.models.HostEventProto.HostNotificationProto) IpAddress(org.onlab.packet.IpAddress) HostProto(org.onosproject.grpc.net.models.HostProtoOuterClass.HostProto)

Example 27 with IpAddress

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

the class KubevirtIpPool method getRangedIps.

/**
 * Obtains the IP address list from the given start and end range.
 *
 * @param start start range
 * @param end   end range
 * @return IP address list from the given start and end range
 * @throws AddressStringException exception
 */
public Set<IpAddress> getRangedIps(String start, String end) throws AddressStringException {
    Set<IpAddress> ips = new HashSet<>();
    IPAddress lower = new IPAddressString(start).toAddress();
    IPAddress upper = new IPAddressString(end).toAddress();
    IPAddressSeqRange range = lower.toSequentialRange(upper);
    for (IPAddress addr : range.getIterable()) {
        ips.add(IpAddress.valueOf(addr.toString()));
    }
    return ips;
}
Also used : IPAddressSeqRange(inet.ipaddr.IPAddressSeqRange) IpAddress(org.onlab.packet.IpAddress) IPAddress(inet.ipaddr.IPAddress) HashSet(java.util.HashSet) IPAddressString(inet.ipaddr.IPAddressString)

Example 28 with IpAddress

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

the class ScaleTestManager method createRoutes.

// Creates the specified number of random routes. Such routes are generated
// using random IP prefices with next hop being an IP address of a randomly
// chosen hosts.
private void createRoutes(int routeCount) {
    List<Host> hosts = ImmutableList.copyOf(hostAdminService.getHosts());
    ImmutableSet.Builder<Route> routes = ImmutableSet.builder();
    for (int i = 0; i < routeCount; i++) {
        IpPrefix prefix = randomIp().toIpPrefix();
        IpAddress nextHop = randomIp(hosts);
        routes.add(new Route(Route.Source.STATIC, prefix, nextHop));
    }
    routeAdminService.update(routes.build());
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) ImmutableSet(com.google.common.collect.ImmutableSet) Host(org.onosproject.net.Host) IpAddress(org.onlab.packet.IpAddress) Route(org.onosproject.routeservice.Route)

Example 29 with IpAddress

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

the class BasicHostOperator method combine.

/**
 * Generates a HostDescription containing fields from a HostDescription and
 * a HostConfig.
 *
 * @param cfg   the host config entity from network config
 * @param descr a HostDescription
 * @return HostDescription based on both sources
 */
public static HostDescription combine(BasicHostConfig cfg, HostDescription descr) {
    if (cfg == null || descr == null) {
        return descr;
    }
    Set<HostLocation> locations = descr.locations();
    Set<HostLocation> cfgLocations = cfg.locations();
    if (cfgLocations != null) {
        locations = cfgLocations.stream().map(hostLocation -> new HostLocation(hostLocation, System.currentTimeMillis())).collect(Collectors.toSet());
    }
    Set<HostLocation> auxLocations = descr.auxLocations();
    Set<HostLocation> cfgAuxLocations = cfg.auxLocations();
    if (cfgAuxLocations != null) {
        auxLocations = cfgAuxLocations.stream().map(hostLocation -> new HostLocation(hostLocation, System.currentTimeMillis())).collect(Collectors.toSet());
    }
    Set<IpAddress> ipAddresses = descr.ipAddress();
    Set<IpAddress> cfgIpAddresses = cfg.ipAddresses();
    if (cfgIpAddresses != null) {
        ipAddresses = cfgIpAddresses;
    }
    SparseAnnotations sa = combine(cfg, descr.annotations());
    return new DefaultHostDescription(descr.hwAddress(), descr.vlan(), locations, auxLocations, ipAddresses, descr.innerVlan(), descr.tpid(), descr.configured(), sa);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress)

Example 30 with IpAddress

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

the class OvsdbPortConfig method changeDeviceIdToNodeId.

// OvsdbNodeId(IP) is used in the adaptor while DeviceId(ovsdb:IP)
// is used in the core. So DeviceId need be changed to OvsdbNodeId.
private OvsdbNodeId changeDeviceIdToNodeId(DeviceId deviceId) {
    String[] splits = deviceId.toString().split(":");
    if (splits.length < 1) {
        return null;
    }
    IpAddress ipAddress = IpAddress.valueOf(splits[1]);
    return new OvsdbNodeId(ipAddress, 0);
}
Also used : IpAddress(org.onlab.packet.IpAddress) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId)

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