Search in sources :

Example 1 with OpenstackVtapCriterion

use of org.onosproject.openstackvtap.api.OpenstackVtapCriterion in project onos by opennetworkinglab.

the class OpenstackVtapCriterionCodec method decode.

@Override
public OpenstackVtapCriterion decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    OpenstackVtapCriterion.Builder cBuilder = DefaultOpenstackVtapCriterion.builder();
    // parse source IP address
    IpPrefix srcIp = IpPrefix.valueOf(IpAddress.valueOf(nullIsIllegal(json.get(SRC_IP).asText(), SRC_IP + MISSING_MESSAGE)), 32);
    // parse destination IP address
    IpPrefix dstIp = IpPrefix.valueOf(IpAddress.valueOf(nullIsIllegal(json.get(DST_IP).asText(), DST_IP + MISSING_MESSAGE)), 32);
    cBuilder.srcIpPrefix(srcIp);
    cBuilder.dstIpPrefix(dstIp);
    // parse IP protocol
    String ipProtoStr = json.get(IP_PROTOCOL).asText();
    if (ipProtoStr != null) {
        cBuilder.ipProtocol(getProtocolTypeFromString(ipProtoStr));
    }
    // parse source port number
    int srcPort = json.get(SRC_PORT).asInt(0);
    // parse destination port number
    int dstPort = json.get(DST_PORT).asInt(0);
    cBuilder.srcTpPort(TpPort.tpPort(srcPort));
    cBuilder.dstTpPort(TpPort.tpPort(dstPort));
    return cBuilder.build();
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) DefaultOpenstackVtapCriterion(org.onosproject.openstackvtap.impl.DefaultOpenstackVtapCriterion) OpenstackVtapCriterion(org.onosproject.openstackvtap.api.OpenstackVtapCriterion) OpenstackVtapUtil.getProtocolTypeFromString(org.onosproject.openstackvtap.util.OpenstackVtapUtil.getProtocolTypeFromString)

Example 2 with OpenstackVtapCriterion

use of org.onosproject.openstackvtap.api.OpenstackVtapCriterion in project onos by opennetworkinglab.

the class OpenstackVtapCriterionCodecTest method testOpenstackVtapCriterionDecode.

/**
 * Tests the openstack vtap criterion decoding.
 */
@Test
public void testOpenstackVtapCriterionDecode() throws IOException {
    OpenstackVtapCriterion criterion = getVtapCriterion("OpenstackVtapCriterion.json");
    assertThat(criterion.srcIpPrefix().address().toString(), is("10.10.10.10"));
    assertThat(criterion.dstIpPrefix().address().toString(), is("20.20.20.20"));
    assertThat(getProtocolStringFromType(criterion.ipProtocol()), is("tcp"));
    assertThat(criterion.srcTpPort().toInt(), is(8080));
    assertThat(criterion.dstTpPort().toInt(), is(9090));
}
Also used : DefaultOpenstackVtapCriterion(org.onosproject.openstackvtap.impl.DefaultOpenstackVtapCriterion) OpenstackVtapCriterion(org.onosproject.openstackvtap.api.OpenstackVtapCriterion) Test(org.junit.Test)

Example 3 with OpenstackVtapCriterion

use of org.onosproject.openstackvtap.api.OpenstackVtapCriterion in project onos by opennetworkinglab.

the class OpenstackVtapCriterionCodecTest method getVtapCriterion.

/**
 * Reads in an openstack vtap criterion from the given resource and decodes it.
 *
 * @param resourceName resource to use to read the JSON for the rule
 * @return decoded openstack vtap criterion
 * @throws IOException if processing the resource fails
 */
private OpenstackVtapCriterion getVtapCriterion(String resourceName) throws IOException {
    InputStream jsonStream = OpenstackVtapCriterionCodecTest.class.getResourceAsStream(resourceName);
    JsonNode json = context.mapper().readTree(jsonStream);
    MatcherAssert.assertThat(json, notNullValue());
    OpenstackVtapCriterion criterion = vtapCriterionCodec.decode((ObjectNode) json, context);
    assertThat(criterion, notNullValue());
    return criterion;
}
Also used : DefaultOpenstackVtapCriterion(org.onosproject.openstackvtap.impl.DefaultOpenstackVtapCriterion) OpenstackVtapCriterion(org.onosproject.openstackvtap.api.OpenstackVtapCriterion) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 4 with OpenstackVtapCriterion

use of org.onosproject.openstackvtap.api.OpenstackVtapCriterion in project onos by opennetworkinglab.

the class DefaultOpenstackVtapCriterionTest method testConstruction.

/**
 * Tests object construction.
 */
@Test
public void testConstruction() {
    OpenstackVtapCriterion criterion = criterion1;
    assertThat(criterion.srcIpPrefix(), is(SRC_IP_PREFIX_1));
    assertThat(criterion.dstIpPrefix(), is(DST_IP_PREFIX_1));
    assertThat(criterion.srcTpPort(), is(SRC_PORT_1));
    assertThat(criterion.dstTpPort(), is(DST_PORT_1));
    assertThat(criterion.ipProtocol(), is(IP_PROTOCOL_1));
}
Also used : OpenstackVtapCriterion(org.onosproject.openstackvtap.api.OpenstackVtapCriterion) Test(org.junit.Test)

Example 5 with OpenstackVtapCriterion

use of org.onosproject.openstackvtap.api.OpenstackVtapCriterion in project onos by opennetworkinglab.

the class OpenstackVtapWebResource method readAndCreateVtap.

private OpenstackVtap readAndCreateVtap(InputStream input) {
    OpenstackVtap.Type type = OpenstackVtap.Type.VTAP_ALL;
    OpenstackVtapCriterion criterion;
    try {
        JsonNode jsonTree = readTreeFromStream(mapper().enable(INDENT_OUTPUT), input);
        String typeStr = jsonTree.path(TYPE).asText();
        if (typeStr != null) {
            type = getVtapTypeFromString(typeStr);
        }
        ObjectNode jsonCriterion = jsonTree.path(CRITERION).deepCopy();
        criterion = codec(OpenstackVtapCriterion.class).decode(jsonCriterion, this);
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
    return vtapService.createVtap(type, criterion);
}
Also used : OpenstackVtap(org.onosproject.openstackvtap.api.OpenstackVtap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) OpenstackVtapCriterion(org.onosproject.openstackvtap.api.OpenstackVtapCriterion) JsonNode(com.fasterxml.jackson.databind.JsonNode) OpenstackVtapUtil.getVtapTypeFromString(org.onosproject.openstackvtap.util.OpenstackVtapUtil.getVtapTypeFromString)

Aggregations

OpenstackVtapCriterion (org.onosproject.openstackvtap.api.OpenstackVtapCriterion)7 DefaultOpenstackVtapCriterion (org.onosproject.openstackvtap.impl.DefaultOpenstackVtapCriterion)4 Test (org.junit.Test)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 OpenstackVtap (org.onosproject.openstackvtap.api.OpenstackVtap)2 InputStream (java.io.InputStream)1 IpPrefix (org.onlab.packet.IpPrefix)1 OpenstackVtapUtil.getProtocolTypeFromString (org.onosproject.openstackvtap.util.OpenstackVtapUtil.getProtocolTypeFromString)1 OpenstackVtapUtil.getVtapTypeFromString (org.onosproject.openstackvtap.util.OpenstackVtapUtil.getVtapTypeFromString)1