Search in sources :

Example 1 with K8sIpam

use of org.onosproject.k8snetworking.api.K8sIpam in project onos by opennetworkinglab.

the class K8sIpamCodecTest method testK8sIpamDecode.

/**
 * Tests the kubernetes IPAM decoding.
 */
@Test
public void testK8sIpamDecode() throws IOException {
    K8sIpam ipam = getK8sIpam("K8sIpam.json");
    assertEquals("10.10.10.2", ipam.ipAddress().toString());
    assertEquals("network-1", ipam.networkId());
}
Also used : DefaultK8sIpam(org.onosproject.k8snetworking.api.DefaultK8sIpam) K8sIpamJsonMatcher.matchesK8sIpam(org.onosproject.k8snetworking.codec.K8sIpamJsonMatcher.matchesK8sIpam) K8sIpam(org.onosproject.k8snetworking.api.K8sIpam) Test(org.junit.Test)

Example 2 with K8sIpam

use of org.onosproject.k8snetworking.api.K8sIpam in project onos by opennetworkinglab.

the class K8sIpamWebResource method allocateIp.

/**
 * Requests for allocating a unique IP address of the given network ID.
 *
 * @param netId     network identifier
 * @return 200 OK with the serialized IPAM JSON string
 * @onos.rsModel K8sIpam
 */
@GET
@Path("{netId}")
@Produces(MediaType.APPLICATION_JSON)
public Response allocateIp(@PathParam("netId") String netId) {
    log.trace("Received IP allocation request of network " + netId);
    K8sNetwork network = nullIsNotFound(networkService.network(netId), NETWORK_ID_NOT_FOUND);
    IpAddress ip = nullIsNotFound(ipamService.allocateIp(network.networkId()), IP_NOT_ALLOCATED);
    ObjectNode root = mapper().createObjectNode();
    String ipamId = network.networkId() + "-" + ip.toString();
    K8sIpam ipam = new DefaultK8sIpam(ipamId, ip, network.networkId());
    root.set(IPAM, codec(K8sIpam.class).encode(ipam, this));
    return ok(root).build();
}
Also used : DefaultK8sIpam(org.onosproject.k8snetworking.api.DefaultK8sIpam) K8sIpam(org.onosproject.k8snetworking.api.K8sIpam) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultK8sIpam(org.onosproject.k8snetworking.api.DefaultK8sIpam) K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) IpAddress(org.onlab.packet.IpAddress) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with K8sIpam

use of org.onosproject.k8snetworking.api.K8sIpam in project onos by opennetworkinglab.

the class K8sIpamManager method initializeIpPool.

@Override
public void initializeIpPool(String networkId, Set<IpAddress> ipAddresses) {
    ipAddresses.forEach(ip -> {
        String ipamId = networkId + "-" + ip;
        K8sIpam ipam = new DefaultK8sIpam(ipamId, ip, networkId);
        k8sIpamStore.createAvailableIp(ipam);
    });
}
Also used : DefaultK8sIpam(org.onosproject.k8snetworking.api.DefaultK8sIpam) K8sIpam(org.onosproject.k8snetworking.api.K8sIpam) DefaultK8sIpam(org.onosproject.k8snetworking.api.DefaultK8sIpam)

Example 4 with K8sIpam

use of org.onosproject.k8snetworking.api.K8sIpam in project onos by opennetworkinglab.

the class K8sIpamCodecTest method testK8sIpamEncode.

/**
 * Tests the kubernetes IPAM encoding.
 */
@Test
public void testK8sIpamEncode() {
    K8sIpam ipam = new DefaultK8sIpam("network-1-10.10.10.10", IpAddress.valueOf("10.10.10.10"), "network-1");
    ObjectNode nodeJson = k8sIpamCodec.encode(ipam, context);
    assertThat(nodeJson, matchesK8sIpam(ipam));
}
Also used : DefaultK8sIpam(org.onosproject.k8snetworking.api.DefaultK8sIpam) K8sIpamJsonMatcher.matchesK8sIpam(org.onosproject.k8snetworking.codec.K8sIpamJsonMatcher.matchesK8sIpam) K8sIpam(org.onosproject.k8snetworking.api.K8sIpam) DefaultK8sIpam(org.onosproject.k8snetworking.api.DefaultK8sIpam) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Test(org.junit.Test)

Example 5 with K8sIpam

use of org.onosproject.k8snetworking.api.K8sIpam in project onos by opennetworkinglab.

the class K8sIpamCodecTest method getK8sIpam.

/**
 * Reads in an kubernetes IPAM from the given resource and decodes it.
 *
 * @param resourceName resource to use to read the JSON for the rule
 * @return decoded kubernetes node
 * @throws IOException if processing the resource fails
 */
private K8sIpam getK8sIpam(String resourceName) throws IOException {
    InputStream jsonStream = K8sIpamCodecTest.class.getResourceAsStream(resourceName);
    JsonNode json = context.mapper().readTree(jsonStream);
    MatcherAssert.assertThat(json, notNullValue());
    K8sIpam node = k8sIpamCodec.decode((ObjectNode) json, context);
    assertThat(node, notNullValue());
    return node;
}
Also used : DefaultK8sIpam(org.onosproject.k8snetworking.api.DefaultK8sIpam) K8sIpamJsonMatcher.matchesK8sIpam(org.onosproject.k8snetworking.codec.K8sIpamJsonMatcher.matchesK8sIpam) K8sIpam(org.onosproject.k8snetworking.api.K8sIpam) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

DefaultK8sIpam (org.onosproject.k8snetworking.api.DefaultK8sIpam)5 K8sIpam (org.onosproject.k8snetworking.api.K8sIpam)5 K8sIpamJsonMatcher.matchesK8sIpam (org.onosproject.k8snetworking.codec.K8sIpamJsonMatcher.matchesK8sIpam)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Test (org.junit.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 InputStream (java.io.InputStream)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 IpAddress (org.onlab.packet.IpAddress)1 K8sNetwork (org.onosproject.k8snetworking.api.K8sNetwork)1