Search in sources :

Example 6 with RedirectPolicy

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

the class RedirectPolicyCodecTest method setUp.

@Before
public void setUp() throws Exception {
    context = new MockCodecContext();
    codec = new RedirectPolicyCodec();
    List<DeviceId> deviceIds = new LinkedList<>();
    deviceIds.add(DeviceId.deviceId("of:0000000000000001"));
    deviceIds.add(DeviceId.deviceId("of:0000000000000002"));
    deviceIds.add(DeviceId.deviceId("of:0000000000000003"));
    redirectPolicy = new RedirectPolicy(Set.copyOf(deviceIds));
}
Also used : RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) MockCodecContext(org.onosproject.codec.impl.MockCodecContext) DeviceId(org.onosproject.net.DeviceId) LinkedList(java.util.LinkedList) Before(org.junit.Before)

Example 7 with RedirectPolicy

use of org.onosproject.segmentrouting.policy.api.RedirectPolicy 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 8 with RedirectPolicy

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

the class PolicyWebResource method createRedirectPolicy.

/**
 * Create a new Redirect Policy.
 *
 * @param input Json for the Redirect Policy
 * @return 200 OK and policyId
 * @onos.rsModel RedirectPolicyCreate
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("redirect")
public Response createRedirectPolicy(InputStream input) {
    PolicyService policyService = get(PolicyService.class);
    ObjectNode root = mapper().createObjectNode();
    try {
        ObjectNode jsonTree = readTreeFromStream(mapper(), input);
        RedirectPolicy redirectPolicy = codec(RedirectPolicy.class).decode(jsonTree, this);
        policyService.addOrUpdatePolicy(redirectPolicy);
        root.put(POLICY_ID, redirectPolicy.policyId().toString());
    } catch (IOException ex) {
        throw new IllegalArgumentException(ex);
    }
    return Response.ok(root).build();
}
Also used : RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) 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)

Example 9 with RedirectPolicy

use of org.onosproject.segmentrouting.policy.api.RedirectPolicy 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

RedirectPolicy (org.onosproject.segmentrouting.policy.api.RedirectPolicy)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 DeviceId (org.onosproject.net.DeviceId)5 PolicyService (org.onosproject.segmentrouting.policy.api.PolicyService)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 Produces (javax.ws.rs.Produces)3 DropPolicy (org.onosproject.segmentrouting.policy.api.DropPolicy)3 Policy (org.onosproject.segmentrouting.policy.api.Policy)3 PolicyType (org.onosproject.segmentrouting.policy.api.Policy.PolicyType)3 PolicyData (org.onosproject.segmentrouting.policy.api.PolicyData)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 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2