Search in sources :

Example 51 with IpAddress

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

the class K8sManagementWebResource method purgeAll.

/**
 * Removes all nodes and hosts.
 *
 * @return 204 NO_CONTENT, 400 BAD_REQUEST if the JSON is malformed, and
 * 304 NOT_MODIFIED without the updated config
 */
@DELETE
@Path("purge/all")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response purgeAll() {
    log.trace(String.format(MESSAGE_ALL, REMOVE));
    Set<String> portIds = networkAdminService.ports().stream().map(K8sPort::portId).collect(Collectors.toSet());
    portIds.forEach(networkAdminService::removePort);
    try {
        sleep(MID_SLEEP_MS);
    } catch (InterruptedException e) {
        log.error("Exception caused during node synchronization...");
    }
    Set<String> masters = nodeAdminService.nodes(K8sNode.Type.MASTER).stream().map(K8sNode::hostname).collect(Collectors.toSet());
    Set<String> workers = nodeAdminService.nodes(K8sNode.Type.MINION).stream().map(K8sNode::hostname).collect(Collectors.toSet());
    for (String hostname : workers) {
        nodeAdminService.removeNode(hostname);
        try {
            sleep(MID_SLEEP_MS);
        } catch (InterruptedException e) {
            log.error("Exception caused during node synchronization...");
        }
    }
    for (String hostname : masters) {
        nodeAdminService.removeNode(hostname);
        try {
            sleep(MID_SLEEP_MS);
        } catch (InterruptedException e) {
            log.error("Exception caused during node synchronization...");
        }
    }
    Set<IpAddress> allHosts = hostAdminService.hosts().stream().map(K8sHost::hostIp).collect(Collectors.toSet());
    for (IpAddress hostIp : allHosts) {
        hostAdminService.removeHost(hostIp);
        try {
            sleep(MID_SLEEP_MS);
        } catch (InterruptedException e) {
            log.error("Exception caused during node synchronization...");
        }
    }
    return Response.noContent().build();
}
Also used : IpAddress(org.onlab.packet.IpAddress) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 52 with IpAddress

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

the class K8sApiConfigCodec method decode.

@Override
public K8sApiConfig decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    JsonNode clusterNameJson = json.get(CLUSTER_NAME);
    String clusterNameStr = "";
    if (clusterNameJson == null) {
        clusterNameStr = DEFAULT_CLUSTER_NAME;
    } else {
        clusterNameStr = clusterNameJson.asText();
    }
    JsonNode segmentIdJson = json.get(SEGMENT_ID);
    int segmentId = DEFAULT_SEGMENT_ID;
    if (segmentIdJson != null) {
        segmentId = segmentIdJson.asInt();
    }
    JsonNode modeJson = json.get(MODE);
    String modeStr = "";
    if (modeJson == null) {
        modeStr = DEFAULT_CONFIG_MODE;
    } else {
        modeStr = modeJson.asText();
    }
    Mode mode = Mode.valueOf(modeStr);
    Scheme scheme = Scheme.valueOf(nullIsIllegal(json.get(SCHEME).asText(), SCHEME + MISSING_MESSAGE));
    IpAddress ipAddress = IpAddress.valueOf(nullIsIllegal(json.get(IP_ADDRESS).asText(), IP_ADDRESS + MISSING_MESSAGE));
    int port = json.get(PORT).asInt();
    K8sApiConfig.Builder builder = DefaultK8sApiConfig.builder().clusterName(clusterNameStr).segmentId(segmentId).mode(mode).scheme(scheme).ipAddress(ipAddress).port(port).state(DISCONNECTED);
    JsonNode dvrJson = json.get(DVR);
    if (dvrJson != null) {
        builder.dvr(dvrJson.asBoolean());
    }
    JsonNode tokenJson = json.get(TOKEN);
    JsonNode caCertDataJson = json.get(CA_CERT_DATA);
    JsonNode clientCertDataJson = json.get(CLIENT_CERT_DATA);
    JsonNode clientKeyDataJson = json.get(CLIENT_KEY_DATA);
    String token = "";
    String caCertData = "";
    String clientCertData = "";
    String clientKeyData = "";
    if (scheme == HTTPS) {
        caCertData = nullIsIllegal(caCertDataJson.asText(), CA_CERT_DATA + MISSING_MESSAGE);
        clientCertData = nullIsIllegal(clientCertDataJson.asText(), CLIENT_CERT_DATA + MISSING_MESSAGE);
        clientKeyData = nullIsIllegal(clientKeyDataJson.asText(), CLIENT_KEY_DATA + MISSING_MESSAGE);
        if (tokenJson != null) {
            token = tokenJson.asText();
        }
    } else {
        if (tokenJson != null) {
            token = tokenJson.asText();
        }
        if (caCertDataJson != null) {
            caCertData = caCertDataJson.asText();
        }
        if (clientCertDataJson != null) {
            clientCertData = clientCertDataJson.asText();
        }
        if (clientKeyDataJson != null) {
            clientKeyData = clientKeyDataJson.asText();
        }
    }
    if (StringUtils.isNotEmpty(token)) {
        builder.token(token);
    }
    if (StringUtils.isNotEmpty(caCertData)) {
        builder.caCertData(caCertData);
    }
    if (StringUtils.isNotEmpty(clientCertData)) {
        builder.clientCertData(clientCertData);
    }
    if (StringUtils.isNotEmpty(clientKeyData)) {
        builder.clientKeyData(clientKeyData);
    }
    JsonNode extNetworkCidrJson = json.get(EXT_NETWORK_CIDR);
    if (extNetworkCidrJson != null) {
        builder.extNetworkCidr(IpPrefix.valueOf(extNetworkCidrJson.asText()));
    }
    Set<HostNodesInfo> infos = new HashSet<>();
    ArrayNode infosJson = (ArrayNode) json.get(HOST_NODES_INFO);
    if (infosJson != null) {
        for (JsonNode infoJson : infosJson) {
            HostNodesInfo info = context.codec(HostNodesInfo.class).decode((ObjectNode) infoJson, context);
            infos.add(info);
        }
        builder.infos(infos);
    }
    return builder.build();
}
Also used : K8sApiConfig(org.onosproject.k8snode.api.K8sApiConfig) DefaultK8sApiConfig(org.onosproject.k8snode.api.DefaultK8sApiConfig) Scheme(org.onosproject.k8snode.api.K8sApiConfig.Scheme) Mode(org.onosproject.k8snode.api.K8sApiConfig.Mode) HostNodesInfo(org.onosproject.k8snode.api.HostNodesInfo) JsonNode(com.fasterxml.jackson.databind.JsonNode) IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) HashSet(java.util.HashSet)

Example 53 with IpAddress

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

the class K8sHostCodec method decode.

@Override
public K8sHost decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    IpAddress hostIp = IpAddress.valueOf(nullIsIllegal(json.get(HOST_IP).asText(), HOST_IP + MISSING_MESSAGE));
    ArrayNode nodeNamesJson = (ArrayNode) json.get(NODE_NAMES);
    Set<String> nodeNames = new HashSet<>();
    nodeNamesJson.forEach(n -> nodeNames.add(n.asText()));
    return DefaultK8sHost.builder().hostIp(hostIp).state(K8sHostState.INIT).nodeNames(nodeNames).build();
}
Also used : IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) HashSet(java.util.HashSet)

Example 54 with IpAddress

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

the class K8sIpamManagerTest method testReleaseIp.

/**
 * Tests if releasing IP address works correctly.
 */
@Test
public void testReleaseIp() {
    createBasicIpPool();
    IpAddress allocatedIp1 = target.allocateIp(NETWORK_ID);
    IpAddress allocatedIp2 = target.allocateIp(NETWORK_ID);
    assertEquals("Number of allocated IPs did not match", 2, target.allocatedIps(NETWORK_ID).size());
    assertEquals("Number of available IPs did not match", 0, target.availableIps(NETWORK_ID).size());
    target.releaseIp(NETWORK_ID, allocatedIp1);
    assertEquals("Number of allocated IPs did not match", 1, target.allocatedIps(NETWORK_ID).size());
    assertEquals("Number of available IPs did not match", 1, target.availableIps(NETWORK_ID).size());
    target.releaseIp(NETWORK_ID, allocatedIp2);
    assertEquals("Number of allocated IPs did not match", 0, target.allocatedIps(NETWORK_ID).size());
    assertEquals("Number of available IPs did not match", 2, target.availableIps(NETWORK_ID).size());
}
Also used : IpAddress(org.onlab.packet.IpAddress) Test(org.junit.Test)

Example 55 with IpAddress

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

the class ReactiveRoutingFib method setUpConnectivityInternetToHost.

@Override
public void setUpConnectivityInternetToHost(IpAddress hostIpAddress) {
    checkNotNull(hostIpAddress);
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    if (hostIpAddress.isIp4()) {
        selector.matchEthType(Ethernet.TYPE_IPV4);
    } else {
        selector.matchEthType(Ethernet.TYPE_IPV6);
    }
    // Match the destination IP prefix at the first hop
    IpPrefix ipPrefix = hostIpAddress.toIpPrefix();
    selector.matchIPDst(ipPrefix);
    // Rewrite the destination MAC address
    MacAddress hostMac = null;
    FilteredConnectPoint egressPoint = null;
    for (Host host : hostService.getHostsByIp(hostIpAddress)) {
        if (host.mac() != null) {
            hostMac = host.mac();
            egressPoint = new FilteredConnectPoint(host.location());
            break;
        }
    }
    if (hostMac == null) {
        hostService.startMonitoringIp(hostIpAddress);
        return;
    }
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setEthDst(hostMac);
    Key key = Key.of(ipPrefix.toString(), appId);
    int priority = ipPrefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
    Set<ConnectPoint> interfaceConnectPoints = interfaceService.getInterfaces().stream().map(intf -> intf.connectPoint()).collect(Collectors.toSet());
    if (interfaceConnectPoints.isEmpty()) {
        log.error("The interface connect points are empty!");
        return;
    }
    Set<FilteredConnectPoint> ingressPoints = new HashSet<>();
    for (ConnectPoint connectPoint : interfaceConnectPoints) {
        if (!connectPoint.equals(egressPoint.connectPoint())) {
            ingressPoints.add(new FilteredConnectPoint(connectPoint));
        }
    }
    MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder().appId(appId).key(key).selector(selector.build()).treatment(treatment.build()).filteredIngressPoints(ingressPoints).filteredEgressPoint(egressPoint).priority(priority).constraints(CONSTRAINTS).build();
    log.trace("Generates ConnectivityInternetToHost intent {}", intent);
    submitReactiveIntent(ipPrefix, intent);
}
Also used : Host(org.onosproject.net.Host) Interface(org.onosproject.net.intf.Interface) LoggerFactory(org.slf4j.LoggerFactory) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) IntentSynchronizationService(org.onosproject.intentsync.IntentSynchronizationService) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Constraint(org.onosproject.net.intent.Constraint) Key(org.onosproject.net.intent.Key) MacAddress(org.onlab.packet.MacAddress) Collections(java.util.Collections) IpPrefix(org.onlab.packet.IpPrefix) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Host(org.onosproject.net.Host) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) Constraint(org.onosproject.net.intent.Constraint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) IpPrefix(org.onlab.packet.IpPrefix) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Key(org.onosproject.net.intent.Key) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) HashSet(java.util.HashSet)

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