Search in sources :

Example 6 with Policy

use of org.onosproject.segmentrouting.policy.api.Policy in project trellis-control by opennetworkinglab.

the class PolicyWebResource method getPolicies.

/**
 * Get all Policies.
 *
 * @return 200 OK will a collection of Policies
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getPolicies() {
    PolicyService policyService = get(PolicyService.class);
    ObjectNode root = mapper().createObjectNode();
    ArrayNode policiesArr = root.putArray(POLICY);
    // Create a filter set contains all PolicyType
    Set<PolicyType> policyTypes = Set.of(PolicyType.values());
    for (PolicyData policyData : policyService.policies(policyTypes)) {
        Policy policy = policyData.policy();
        switch(policy.policyType()) {
            case DROP:
                policiesArr.add(codec(DropPolicy.class).encode((DropPolicy) policy, this));
                break;
            case REDIRECT:
                policiesArr.add(codec(RedirectPolicy.class).encode((RedirectPolicy) policy, this));
                break;
            default:
                continue;
        }
    }
    return Response.ok(root).build();
}
Also used : DropPolicy(org.onosproject.segmentrouting.policy.api.DropPolicy) Policy(org.onosproject.segmentrouting.policy.api.Policy) RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) PolicyType(org.onosproject.segmentrouting.policy.api.Policy.PolicyType) RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PolicyService(org.onosproject.segmentrouting.policy.api.PolicyService) PolicyData(org.onosproject.segmentrouting.policy.api.PolicyData) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) DropPolicy(org.onosproject.segmentrouting.policy.api.DropPolicy) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with Policy

use of org.onosproject.segmentrouting.policy.api.Policy in project trellis-control by opennetworkinglab.

the class PolicyWebResource method getDropPolicies.

/**
 * Get all Drop Policies.
 *
 * @return 200 OK will a collection of Dop Policies
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("drop")
public Response getDropPolicies() {
    PolicyService policyService = get(PolicyService.class);
    ObjectNode root = mapper().createObjectNode();
    ArrayNode policiesArr = root.putArray(POLICY);
    Set<PolicyType> policyTypes = Set.of(PolicyType.DROP);
    for (PolicyData policyData : policyService.policies(policyTypes)) {
        Policy policy = policyData.policy();
        policiesArr.add(codec(DropPolicy.class).encode((DropPolicy) policy, this));
    }
    return Response.ok(root).build();
}
Also used : DropPolicy(org.onosproject.segmentrouting.policy.api.DropPolicy) Policy(org.onosproject.segmentrouting.policy.api.Policy) RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) PolicyType(org.onosproject.segmentrouting.policy.api.Policy.PolicyType) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PolicyService(org.onosproject.segmentrouting.policy.api.PolicyService) PolicyData(org.onosproject.segmentrouting.policy.api.PolicyData) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) DropPolicy(org.onosproject.segmentrouting.policy.api.DropPolicy) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with Policy

use of org.onosproject.segmentrouting.policy.api.Policy in project trellis-control by opennetworkinglab.

the class PolicyWebResource method getRedirectPolicies.

/**
 * Get all Redirect Policies.
 *
 * @return 200 OK will a collection of Redirect Policies
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("redirect")
public Response getRedirectPolicies() {
    PolicyService policyService = get(PolicyService.class);
    ObjectNode root = mapper().createObjectNode();
    ArrayNode policiesArr = root.putArray(POLICY);
    Set<PolicyType> policyTypes = Set.of(PolicyType.REDIRECT);
    for (PolicyData policyData : policyService.policies(policyTypes)) {
        Policy policy = policyData.policy();
        policiesArr.add(codec(RedirectPolicy.class).encode((RedirectPolicy) policy, this));
    }
    return Response.ok(root).build();
}
Also used : DropPolicy(org.onosproject.segmentrouting.policy.api.DropPolicy) Policy(org.onosproject.segmentrouting.policy.api.Policy) RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) PolicyType(org.onosproject.segmentrouting.policy.api.Policy.PolicyType) RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PolicyService(org.onosproject.segmentrouting.policy.api.PolicyService) PolicyData(org.onosproject.segmentrouting.policy.api.PolicyData) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)5 Lists (com.google.common.collect.Lists)5 Maps (com.google.common.collect.Maps)5 HashFunction (com.google.common.hash.HashFunction)5 Hashing (com.google.common.hash.Hashing)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Map (java.util.Map)5 Optional (java.util.Optional)5 Set (java.util.Set)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 ExecutorService (java.util.concurrent.ExecutorService)5 Executors (java.util.concurrent.Executors)5 Collectors (java.util.stream.Collectors)5 Sets (org.glassfish.jersey.internal.guava.Sets)5 MacAddress (org.onlab.packet.MacAddress)5 KryoNamespace (org.onlab.util.KryoNamespace)5 PredictableExecutor (org.onlab.util.PredictableExecutor)5 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)5 ClusterService (org.onosproject.cluster.ClusterService)5