use of org.onosproject.k8snetworking.api.K8sNetwork in project onos by opennetworkinglab.
the class K8sNetworkWebResource method createNetwork.
/**
* Creates a network from the JSON input stream.
*
* @param input network JSON input stream
* @return 201 CREATED if the JSON is correct, 400 BAD_REQUEST if the JSON
* is invalid or duplicated network already exists
* @onos.rsModel K8sNetwork
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createNetwork(InputStream input) {
log.trace(String.format(MESSAGE, "CREATE"));
URI location;
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), input);
final K8sNetwork network = codec(K8sNetwork.class).decode(jsonTree, this);
adminService.createNetwork(network);
location = new URI(network.networkId());
} catch (IOException | URISyntaxException e) {
throw new IllegalArgumentException(e);
}
return Response.created(location).build();
}
use of org.onosproject.k8snetworking.api.K8sNetwork in project onos by opennetworkinglab.
the class K8sNetworkListCommand method json.
private String json(List<K8sNetwork> networks) {
ObjectMapper mapper = new ObjectMapper();
ArrayNode result = mapper.createArrayNode();
for (K8sNetwork network : networks) {
result.add(jsonForEntity(network, K8sNetwork.class));
}
return prettyJson(mapper, result.toString());
}
use of org.onosproject.k8snetworking.api.K8sNetwork in project onos by opennetworkinglab.
the class K8sPortListCommand method doExecute.
@Override
protected void doExecute() {
K8sNetworkService service = get(K8sNetworkService.class);
List<K8sPort> ports = Lists.newArrayList(service.ports());
ports.sort(Comparator.comparing(K8sPort::networkId));
String format = genFormatString(ImmutableList.of(CLI_ID_LENGTH, CLI_NAME_LENGTH, CLI_MAC_ADDRESS_LENGTH, CLI_IP_ADDRESSES_LENGTH));
if (!Strings.isNullOrEmpty(networkId)) {
ports.removeIf(port -> !port.networkId().equals(networkId));
}
if (outputJson()) {
print("%s", json(ports));
} else {
print(format, "ID", "Network", "MAC Address", "Fixed IPs");
for (K8sPort port : ports) {
K8sNetwork k8sNet = service.network(port.networkId());
print(format, StringUtils.substring(port.portId(), 0, CLI_ID_LENGTH - CLI_MARGIN_LENGTH), k8sNet == null ? "" : StringUtils.substring(k8sNet.name(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(port.macAddress().toString(), 0, CLI_MAC_ADDRESS_LENGTH - CLI_MARGIN_LENGTH), port.ipAddress() == null ? "" : port.ipAddress());
}
}
}
use of org.onosproject.k8snetworking.api.K8sNetwork in project onos by opennetworkinglab.
the class K8sRoutingSnatHandler method setExtToContainerRule.
private void setExtToContainerRule(K8sNode k8sNode, K8sPort k8sPort, boolean install) {
K8sNetwork net = k8sNetworkService.network(k8sPort.networkId());
if (net == null) {
return;
}
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(k8sPort.ipAddress(), HOST_PREFIX));
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setOutput(k8sNode.extToIntgPatchPortNum());
k8sFlowRuleService.setRule(appId, k8sNode.extBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_STATEFUL_SNAT_RULE, POD_RESOLUTION_TABLE, install);
}
use of org.onosproject.k8snetworking.api.K8sNetwork in project onos by opennetworkinglab.
the class K8sRoutingSnatHandler method setExtSnatUpstreamRule.
private void setExtSnatUpstreamRule(K8sNode k8sNode, boolean install) {
K8sNetwork net = k8sNetworkService.network(k8sNode.hostname());
if (net == null) {
return;
}
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchInPort(k8sNode.extToIntgPatchPortNum()).matchEthDst(DEFAULT_GATEWAY_MAC).build();
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
if (install) {
ExtensionTreatment natTreatment = RulePopulatorUtil.niciraConnTrackTreatmentBuilder(driverService, k8sNode.extBridge()).commit(true).natFlag(CT_NAT_SRC_FLAG).natAction(true).natIp(k8sNode.extBridgeIp()).natPortMin(TpPort.tpPort(TP_PORT_MINIMUM_NUM)).natPortMax(TpPort.tpPort(TP_PORT_MAXIMUM_NUM)).build();
tBuilder.extension(natTreatment, k8sNode.extBridge()).setEthSrc(k8sNode.extBridgeMac()).setEthDst(k8sNode.extGatewayMac());
if (k8sNode.mode() == PASSTHROUGH) {
tBuilder.setOutput(k8sNode.extToRouterPortNum());
} else {
if (MacAddress.valueOf(DEFAULT_EXTERNAL_GATEWAY_MAC).equals(k8sNode.extGatewayMac())) {
tBuilder.setOutput(k8sNode.extIntfPortNum());
} else {
tBuilder.setOutput(k8sNode.extBridgePortNum());
}
}
}
k8sFlowRuleService.setRule(appId, k8sNode.extBridge(), selector, tBuilder.build(), PRIORITY_STATEFUL_SNAT_RULE, EXT_ENTRY_TABLE, install);
}
Aggregations