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