Search in sources :

Example 11 with K8sPort

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

the class K8sSwitchingHostProvider method processPortRemoved.

/**
 * Processes port removal event.
 *
 * @param port ONOS port
 */
private void processPortRemoved(Port port) {
    ConnectPoint connectPoint = new ConnectPoint(port.element().id(), port.number());
    Set<Host> hosts = hostService.getConnectedHosts(connectPoint);
    hosts.forEach(h -> hostProviderService.hostVanished(h.id()));
    K8sPort k8sPort = portToK8sPortByName(port);
    if (k8sPort == null) {
        k8sPort = portToK8sPortByMac(port);
        if (k8sPort == null) {
            log.warn(ERR_ADD_HOST + "Kubernetes port for {} not found", port);
            return;
        }
    }
    k8sNetworkService.removePort(k8sPort.portId());
}
Also used : Host(org.onosproject.net.Host) K8sPort(org.onosproject.k8snetworking.api.K8sPort) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 12 with K8sPort

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

the class K8sPortWebResource method updatePort.

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

Example 13 with K8sPort

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

the class K8sPortCodecTest method testK8sPortDecode.

/**
 * Tests the kubernetes port decoding.
 */
@Test
public void testK8sPortDecode() throws IOException {
    K8sPort port = getK8sPort("K8sPort.json");
    assertEquals("network-1", port.networkId());
    assertEquals("port-1", port.portId());
    assertEquals("00:11:22:33:44:55", port.macAddress().toString());
    assertEquals("10.10.10.10", port.ipAddress().toString());
    assertEquals("of:0000000000000001", port.deviceId().toString());
    assertEquals("1", port.portNumber().toString());
    assertEquals("ACTIVE", port.state().name());
}
Also used : K8sPort(org.onosproject.k8snetworking.api.K8sPort) K8sPortJsonMatcher.matchesK8sPort(org.onosproject.k8snetworking.codec.K8sPortJsonMatcher.matchesK8sPort) DefaultK8sPort(org.onosproject.k8snetworking.api.DefaultK8sPort) Test(org.junit.Test)

Example 14 with K8sPort

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

the class K8sPortCodecTest method getK8sPort.

/**
 * Reads in an kubernetes port from the given resource and decodes it.
 *
 * @param resourceName resource to use to read the JSON for the rule
 * @return decoded kubernetes port
 * @throws IOException if processing the resource fails
 */
private K8sPort getK8sPort(String resourceName) throws IOException {
    InputStream jsonStream = K8sPortCodecTest.class.getResourceAsStream(resourceName);
    JsonNode json = context.mapper().readTree(jsonStream);
    MatcherAssert.assertThat(json, notNullValue());
    K8sPort port = k8sPortCodec.decode((ObjectNode) json, context);
    assertThat(port, notNullValue());
    return port;
}
Also used : InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) K8sPort(org.onosproject.k8snetworking.api.K8sPort) K8sPortJsonMatcher.matchesK8sPort(org.onosproject.k8snetworking.codec.K8sPortJsonMatcher.matchesK8sPort) DefaultK8sPort(org.onosproject.k8snetworking.api.DefaultK8sPort)

Example 15 with K8sPort

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

the class K8sPortCodecTest method testK8sPortEncode.

/**
 * Tests the kubernetes port encoding.
 */
@Test
public void testK8sPortEncode() {
    K8sPort port = DefaultK8sPort.builder().networkId("network-1").portId("port-1").deviceId(DeviceId.deviceId("of:0000000000000001")).ipAddress(IpAddress.valueOf("10.10.10.2")).macAddress(MacAddress.valueOf("00:11:22:33:44:55")).portNumber(PortNumber.portNumber(1)).state(ACTIVE).build();
    ObjectNode nodeJson = k8sPortCodec.encode(port, context);
    assertThat(nodeJson, matchesK8sPort(port));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) K8sPort(org.onosproject.k8snetworking.api.K8sPort) K8sPortJsonMatcher.matchesK8sPort(org.onosproject.k8snetworking.codec.K8sPortJsonMatcher.matchesK8sPort) DefaultK8sPort(org.onosproject.k8snetworking.api.DefaultK8sPort) Test(org.junit.Test)

Aggregations

K8sPort (org.onosproject.k8snetworking.api.K8sPort)15 DefaultK8sPort (org.onosproject.k8snetworking.api.DefaultK8sPort)5 K8sNetwork (org.onosproject.k8snetworking.api.K8sNetwork)5 Set (java.util.Set)4 MacAddress (org.onlab.packet.MacAddress)4 K8sNetworkService (org.onosproject.k8snetworking.api.K8sNetworkService)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ExecutorService (java.util.concurrent.ExecutorService)3 IpAddress (org.onlab.packet.IpAddress)3 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)3 CoreService (org.onosproject.core.CoreService)3 K8S_NETWORKING_APP_ID (org.onosproject.k8snetworking.api.Constants.K8S_NETWORKING_APP_ID)3 K8sPortJsonMatcher.matchesK8sPort (org.onosproject.k8snetworking.codec.K8sPortJsonMatcher.matchesK8sPort)3 DeviceId (org.onosproject.net.DeviceId)3 Strings (com.google.common.base.Strings)2 IOException (java.io.IOException)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 VlanId (org.onlab.packet.VlanId)2