Search in sources :

Example 1 with KubevirtPeerRouter

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();
}
Also used : KubevirtPeerRouter(org.onosproject.kubevirtnetworking.api.KubevirtPeerRouter) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) MacAddress(org.onlab.packet.MacAddress) KubevirtRouter(org.onosproject.kubevirtnetworking.api.KubevirtRouter) DefaultKubevirtRouter(org.onosproject.kubevirtnetworking.api.DefaultKubevirtRouter) IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) HashSet(java.util.HashSet)

Example 2 with KubevirtPeerRouter

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));
}
Also used : KubevirtPeerRouter(org.onosproject.kubevirtnetworking.api.KubevirtPeerRouter) KubevirtRouter(org.onosproject.kubevirtnetworking.api.KubevirtRouter)

Example 3 with KubevirtPeerRouter

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));
}
Also used : KubevirtPeerRouter(org.onosproject.kubevirtnetworking.api.KubevirtPeerRouter) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) KubevirtRouter(org.onosproject.kubevirtnetworking.api.KubevirtRouter) DefaultKubevirtRouter(org.onosproject.kubevirtnetworking.api.DefaultKubevirtRouter) KubevirtRouterJsonMatcher.matchesKubevirtRouter(org.onosproject.kubevirtnetworking.codec.KubevirtRouterJsonMatcher.matchesKubevirtRouter) Test(org.junit.Test)

Aggregations

KubevirtPeerRouter (org.onosproject.kubevirtnetworking.api.KubevirtPeerRouter)3 KubevirtRouter (org.onosproject.kubevirtnetworking.api.KubevirtRouter)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DefaultKubevirtRouter (org.onosproject.kubevirtnetworking.api.DefaultKubevirtRouter)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 IpAddress (org.onlab.packet.IpAddress)1 MacAddress (org.onlab.packet.MacAddress)1 KubevirtRouterJsonMatcher.matchesKubevirtRouter (org.onosproject.kubevirtnetworking.codec.KubevirtRouterJsonMatcher.matchesKubevirtRouter)1