Search in sources :

Example 6 with TrafficMatch

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);
}
Also used : TrafficMatch(org.onosproject.segmentrouting.policy.api.TrafficMatch) MockCodecContext(org.onosproject.codec.impl.MockCodecContext) TrafficMatchPriority(org.onosproject.segmentrouting.policy.api.TrafficMatchPriority) Before(org.junit.Before)

Example 7 with TrafficMatch

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();
}
Also used : TrafficMatchData(org.onosproject.segmentrouting.policy.api.TrafficMatchData) TrafficMatch(org.onosproject.segmentrouting.policy.api.TrafficMatch) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PolicyService(org.onosproject.segmentrouting.policy.api.PolicyService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with TrafficMatch

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();
}
Also used : TrafficMatch(org.onosproject.segmentrouting.policy.api.TrafficMatch) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PolicyService(org.onosproject.segmentrouting.policy.api.PolicyService) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

TrafficMatch (org.onosproject.segmentrouting.policy.api.TrafficMatch)8 PolicyService (org.onosproject.segmentrouting.policy.api.PolicyService)5 TrafficMatchPriority (org.onosproject.segmentrouting.policy.api.TrafficMatchPriority)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 TrafficSelector (org.onosproject.net.flow.TrafficSelector)4 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)3 PolicyId (org.onosproject.segmentrouting.policy.api.PolicyId)3 TrafficMatchId (org.onosproject.segmentrouting.policy.api.TrafficMatchId)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 HashFunction (com.google.common.hash.HashFunction)2 Hashing (com.google.common.hash.Hashing)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutorService (java.util.concurrent.ExecutorService)2