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();
}
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();
}
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();
}
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());
}
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);
}
Aggregations