use of org.onosproject.kubevirtnetworking.api.KubevirtRouter in project onos by opennetworkinglab.
the class KubevirtListRouterCommand method doExecute.
@Override
protected void doExecute() throws Exception {
KubevirtRouterService service = get(KubevirtRouterService.class);
List<KubevirtRouter> routers = Lists.newArrayList(service.routers());
routers.sort(Comparator.comparing(KubevirtRouter::name));
String format = genFormatString(ImmutableList.of(CLI_NAME_LENGTH, CLI_FLAG_LENGTH, CLI_IP_ADDRESSES_LENGTH, CLI_IP_ADDRESS_LENGTH, CLI_NAME_LENGTH));
if (outputJson()) {
print("%s", json(routers));
} else {
print(format, "Name", "SNAT", "Internal", "External", "GatewayNode");
for (KubevirtRouter router : routers) {
Set<String> internalNetworks = router.internal();
String externalNetwork = router.external().values().stream().findAny().orElse(null);
String internal = internalNetworks.size() == 0 ? "[]" : internalNetworks.toString();
String external = externalNetwork == null ? "[]" : externalNetwork;
String gwNode = router.electedGateway() == null ? "N/A" : router.electedGateway();
print(format, StringUtils.substring(router.name(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(String.valueOf(router.enableSnat()), 0, CLI_FLAG_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(internal, 0, CLI_IP_ADDRESSES_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(external, 0, CLI_IP_ADDRESS_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(gwNode, 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH));
}
}
}
use of org.onosproject.kubevirtnetworking.api.KubevirtRouter in project onos by opennetworkinglab.
the class KubevirtRouterCodec method decode.
@Override
public KubevirtRouter decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
String name = nullIsIllegal(json.get(NAME).asText(), NAME + MISSING_MESSAGE);
String vrouterMac = nullIsIllegal(json.get(MAC_ADDRESS).asText(), MAC_ADDRESS + MISSING_MESSAGE);
KubevirtRouter.Builder builder = DefaultKubevirtRouter.builder().name(name).mac(MacAddress.valueOf(vrouterMac));
JsonNode descriptionJson = json.get(DESCRIPTION);
if (descriptionJson != null) {
builder.description(descriptionJson.asText());
}
JsonNode enableSnatJson = json.get(ENABLE_SNAT);
if (enableSnatJson != null) {
builder.enableSnat(enableSnatJson.asBoolean());
}
JsonNode electedGwJson = json.get(GATEWAY);
if (electedGwJson != null) {
builder.electedGateway(electedGwJson.asText());
}
ArrayNode internalJson = (ArrayNode) json.get(INTERNAL);
Set<String> internal = new HashSet<>();
if (internalJson != null) {
for (int i = 0; i < internalJson.size(); i++) {
internal.add(internalJson.get(i).asText());
}
builder.internal(internal);
}
ObjectNode externalJson = (ObjectNode) json.get(EXTERNAL);
if (externalJson != null) {
Map<String, String> external = ImmutableMap.of(externalJson.get(IP_ADDRESS).asText(), externalJson.get(NETWORK).asText());
builder.external(external);
}
ObjectNode peerRouterJson = (ObjectNode) json.get(PEER_ROUTER);
if (peerRouterJson != null) {
JsonNode ipJson = peerRouterJson.get(IP_ADDRESS);
JsonNode macJson = peerRouterJson.get(MAC_ADDRESS);
if (ipJson != null && macJson != null) {
IpAddress ip = IpAddress.valueOf(ipJson.asText());
MacAddress mac = MacAddress.valueOf(macJson.asText());
KubevirtPeerRouter peer = new KubevirtPeerRouter(ip, mac);
builder.peerRouter(peer);
}
// if mac address is not specified, we will not add mac address to peer router
if (ipJson != null && macJson == null) {
IpAddress ip = IpAddress.valueOf(ipJson.asText());
KubevirtPeerRouter peer = new KubevirtPeerRouter(ip, null);
builder.peerRouter(peer);
}
}
return builder.build();
}
use of org.onosproject.kubevirtnetworking.api.KubevirtRouter in project onos by opennetworkinglab.
the class KubevirtNetworkHandler method setGatewayRuleToWorkerNodeWhenNodeCreated.
private void setGatewayRuleToWorkerNodeWhenNodeCreated(KubevirtNode node, KubevirtNetwork network) {
KubevirtRouter router = getRouterForKubevirtNetwork(kubevirtRouterService, network);
if (router == null) {
return;
}
KubevirtNode electedGw = gatewayNodeForSpecifiedRouter(nodeService, router);
if (electedGw == null) {
return;
}
setDefaultGatewayRuleToWorkerNodeTunBridge(router, network, electedGw.intgBridge(), node, true);
}
use of org.onosproject.kubevirtnetworking.api.KubevirtRouter in project onos by opennetworkinglab.
the class KubevirtNetworkHandler method setGatewayArpRulesForTenantNetwork.
private void setGatewayArpRulesForTenantNetwork(KubevirtNode node, KubevirtNetwork network) {
KubevirtRouter router = getRouterForKubevirtNetwork(kubevirtRouterService, network);
if (router == null) {
return;
}
KubevirtNode electedGw = gatewayNodeForSpecifiedRouter(nodeService, router);
if (electedGw == null) {
return;
}
setGatewayArpRuleForTenantInternalNetwork(router, network, TENANT_ARP_TABLE, electedGw.intgBridge(), network.tenantDeviceId(node.hostname()), true);
}
use of org.onosproject.kubevirtnetworking.api.KubevirtRouter in project onos by opennetworkinglab.
the class KubevirtRouterWatcher method parseKubevirtRouter.
private KubevirtRouter parseKubevirtRouter(String resource) {
try {
ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.readTree(resource);
ObjectNode spec = (ObjectNode) json.get("spec");
KubevirtRouter router = codec(KubevirtRouter.class).decode(spec, this);
KubevirtRouter existing = routerService.router(router.name());
if (existing == null) {
return router;
} else {
return router.updatedElectedGateway(existing.electedGateway());
}
} catch (IOException e) {
log.error("Failed to parse kubevirt router object");
}
return null;
}
Aggregations