use of org.onosproject.kubevirtnetworking.api.KubevirtPeerRouter 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.KubevirtPeerRouter in project onos by opennetworkinglab.
the class KubevirtRouterManager method updatePeerRouterMac.
@Override
public void updatePeerRouterMac(String name, MacAddress mac) {
KubevirtRouter router = kubevirtRouterStore.router(name);
if (router == null) {
log.warn("The router is not found with the given name {}", name);
return;
}
KubevirtPeerRouter existing = router.peerRouter();
if (existing == null) {
log.warn("The peer router is not found with the given name {}", name);
return;
}
KubevirtPeerRouter updated = new KubevirtPeerRouter(existing.ipAddress(), mac);
kubevirtRouterStore.updateRouter(router.updatePeerRouter(updated));
}
use of org.onosproject.kubevirtnetworking.api.KubevirtPeerRouter in project onos by opennetworkinglab.
the class KubevirtRouterCodecTest method testKubevirtRouterEncode.
/**
* Tests the kubevirt router encoding.
*/
@Test
public void testKubevirtRouterEncode() {
KubevirtPeerRouter peerRouter = new KubevirtPeerRouter(IpAddress.valueOf("10.10.10.10"), MacAddress.valueOf("11:22:33:44:55:66"));
KubevirtRouter router = DefaultKubevirtRouter.builder().name("router-1").enableSnat(true).mac(MacAddress.valueOf("11:22:33:44:55:66")).description("router-1").internal(ImmutableSet.of("vlan-1")).external(ImmutableMap.of("10.10.10.20", "flat-1")).peerRouter(peerRouter).electedGateway("gatewayNode").build();
ObjectNode routerJson = kubevirtRouterCodec.encode(router, context);
assertThat(routerJson, matchesKubevirtRouter(router));
}
Aggregations