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);
}
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));
}
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();
}
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();
}
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();
}
Aggregations