Search in sources :

Example 11 with K8sNetwork

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 12 with K8sNetwork

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());
}
Also used : K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 13 with K8sNetwork

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());
        }
    }
}
Also used : K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) K8sNetworkService(org.onosproject.k8snetworking.api.K8sNetworkService) K8sPort(org.onosproject.k8snetworking.api.K8sPort) K8sNetworkingUtil.genFormatString(org.onosproject.k8snetworking.util.K8sNetworkingUtil.genFormatString)

Example 14 with K8sNetwork

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);
}
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 15 with K8sNetwork

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);
}
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) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment)

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