Search in sources :

Example 16 with K8sNetwork

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

the class K8sRoutingSnatHandler method setContainerToExtRule.

private void setContainerToExtRule(K8sNode k8sNode, boolean install) {
    K8sNetwork net = k8sNetworkService.network(k8sNode.hostname());
    if (net == null) {
        return;
    }
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchTunnelId(Long.valueOf(net.segmentId())).matchEthDst(DEFAULT_GATEWAY_MAC);
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setOutput(k8sNode.intgToExtPatchPortNum());
    k8sFlowRuleService.setRule(appId, k8sNode.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_EXTERNAL_ROUTING_RULE, ROUTING_TABLE, install);
}
Also used : K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 17 with K8sNetwork

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

the class K8sNetworkCodecTest method testK8sNetworkEncode.

/**
 * Tests the kubernetes network encoding.
 */
@Test
public void testK8sNetworkEncode() {
    K8sNetwork network = DefaultK8sNetwork.builder().networkId("network-1").name("network-1").segmentId("1").type(K8sNetwork.Type.VXLAN).cidr("10.10.0.0/24").mtu(1500).build();
    ObjectNode nodeJson = k8sNetworkCodec.encode(network, context);
    assertThat(nodeJson, matchesK8sNetwork(network));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) K8sNetworkJsonMatcher.matchesK8sNetwork(org.onosproject.k8snetworking.codec.K8sNetworkJsonMatcher.matchesK8sNetwork) K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) DefaultK8sNetwork(org.onosproject.k8snetworking.api.DefaultK8sNetwork) Test(org.junit.Test)

Example 18 with K8sNetwork

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

the class K8sIpamWebResource method releaseIp.

/**
 * Requests for releasing the given IP address.
 *
 * @param netId     network identifier
 * @param ip        IP address
 * @return 204 NO CONTENT
 */
@DELETE
@Path("{netId}/{ip}")
public Response releaseIp(@PathParam("netId") String netId, @PathParam("ip") String ip) {
    log.trace("Received IP release request of network " + netId);
    K8sNetwork network = nullIsNotFound(networkService.network(netId), NETWORK_ID_NOT_FOUND);
    ipamService.releaseIp(network.networkId(), IpAddress.valueOf(ip));
    return Response.noContent().build();
}
Also used : K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 19 with K8sNetwork

use of org.onosproject.k8snetworking.api.K8sNetwork 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 20 with K8sNetwork

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

the class K8sNetworkWebResource method updateNetwork.

/**
 * Updates the network with the specified identifier.
 *
 * @param id    network identifier
 * @param input network JSON input stream
 * @return 200 OK with the updated network, 400 BAD_REQUEST if the requested
 * network does not exist
 * @onos.rsModel K8sNetwork
 */
@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateNetwork(@PathParam("id") String id, InputStream input) {
    log.trace(String.format(MESSAGE, "UPDATED"));
    try {
        ObjectNode jsonTree = readTreeFromStream(mapper(), input);
        JsonNode specifiedNetworkId = jsonTree.get("networkId");
        if (specifiedNetworkId != null && !specifiedNetworkId.asText().equals(id)) {
            throw new IllegalArgumentException(NETWORK_INVALID);
        }
        final K8sNetwork network = codec(K8sNetwork.class).decode(jsonTree, this);
        adminService.updateNetwork(network);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
    return Response.ok().build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

K8sNetwork (org.onosproject.k8snetworking.api.K8sNetwork)21 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)6 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)6 TrafficSelector (org.onosproject.net.flow.TrafficSelector)6 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 Path (javax.ws.rs.Path)4 K8sNetworkService (org.onosproject.k8snetworking.api.K8sNetworkService)4 K8sPort (org.onosproject.k8snetworking.api.K8sPort)4 Set (java.util.Set)3 IpAddress (org.onlab.packet.IpAddress)3 MacAddress (org.onlab.packet.MacAddress)3 DefaultK8sNetwork (org.onosproject.k8snetworking.api.DefaultK8sNetwork)3 K8sNetworkJsonMatcher.matchesK8sNetwork (org.onosproject.k8snetworking.codec.K8sNetworkJsonMatcher.matchesK8sNetwork)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ExecutorService (java.util.concurrent.ExecutorService)2 Collectors (java.util.stream.Collectors)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 VlanId (org.onlab.packet.VlanId)2