use of org.onosproject.segmentrouting.policy.api.TrafficMatch in project trellis-control by opennetworkinglab.
the class TrafficMatchCodecTest method setUp.
@Before
public void setUp() throws Exception {
context = new MockCodecContext();
codec = new TrafficMatchCodec();
trafficSelector = DefaultTrafficSelector.builder().matchIPProtocol((byte) 0x06).matchIPSrc(Ip4Address.valueOf("10.0.0.1").toIpPrefix()).matchIPDst(Ip4Address.valueOf("10.0.0.2").toIpPrefix()).matchTcpSrc(TpPort.tpPort(80)).matchTcpDst(TpPort.tpPort(81)).build();
policyId = PolicyId.of("DROP");
TrafficMatchPriority trafficMatchPriority = new TrafficMatchPriority(60000);
trafficMatch = new TrafficMatch(trafficSelector, policyId, trafficMatchPriority);
}
use of org.onosproject.segmentrouting.policy.api.TrafficMatch in project trellis-control by opennetworkinglab.
the class PolicyWebResource method getTrafficMatches.
/**
* Get all Traffic Matches.
*
* @return 200 OK will a collection of Traffic Matches
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("trafficmatch")
public Response getTrafficMatches() {
PolicyService policyService = get(PolicyService.class);
ObjectNode root = mapper().createObjectNode();
ArrayNode trafficMatchArr = root.putArray(TRAFFIC_MATCH);
for (TrafficMatchData trafficMatchData : policyService.trafficMatches()) {
TrafficMatch trafficMatch = trafficMatchData.trafficMatch();
trafficMatchArr.add(codec(TrafficMatch.class).encode(trafficMatch, this));
}
return Response.ok(root).build();
}
use of org.onosproject.segmentrouting.policy.api.TrafficMatch in project trellis-control by opennetworkinglab.
the class PolicyWebResource method createTrafficMatch.
/**
* Create a new Traffic Match.
*
* @param input Json for the Traffic Match
* @return status of the request - CREATED and TrafficMatchId if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel TrafficMatchCreate
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("trafficmatch")
public Response createTrafficMatch(InputStream input) {
PolicyService policyService = get(PolicyService.class);
ObjectNode root = mapper().createObjectNode();
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), input);
TrafficMatch trafficMatch = codec(TrafficMatch.class).decode(jsonTree, this);
if (trafficMatch.trafficSelector().equals(DefaultTrafficSelector.emptySelector())) {
throw new IllegalArgumentException(EMPTY_TRAFFIC_SELECTOR);
}
policyService.addOrUpdateTrafficMatch(trafficMatch);
root.put(TRAFFIC_MATCH_ID, trafficMatch.trafficMatchId().toString());
} catch (IOException | IllegalArgumentException ex) {
throw new IllegalArgumentException(ex);
}
return Response.ok(root).build();
}
Aggregations