Search in sources :

Example 1 with DropPolicy

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

the class DropPolicyCodecTest method testDecode.

@Test
public void testDecode() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    InputStream jsonStream1 = RedirectPolicyCodecTest.class.getResourceAsStream("/droppolicy.json");
    ObjectNode json = mapper.readTree(jsonStream1).deepCopy();
    DropPolicy actual = codec.decode(json, context);
    assertEquals(dropPolicy, actual);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InputStream(java.io.InputStream) DropPolicy(org.onosproject.segmentrouting.policy.api.DropPolicy) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with DropPolicy

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

the class DropPolicyCodecTest method setUp.

@Before
public void setUp() throws Exception {
    context = new MockCodecContext();
    codec = new DropPolicyCodec();
    dropPolicy = new DropPolicy();
}
Also used : MockCodecContext(org.onosproject.codec.impl.MockCodecContext) DropPolicy(org.onosproject.segmentrouting.policy.api.DropPolicy) Before(org.junit.Before)

Example 3 with DropPolicy

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

the class PolicyWebResource method createDropPolicy.

/**
 * Create a new Drop Policy.
 *
 * @return 200 OK and policyId
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("drop")
public Response createDropPolicy() {
    PolicyService policyService = get(PolicyService.class);
    ObjectNode root = mapper().createObjectNode();
    DropPolicy dropPolicy = new DropPolicy();
    policyService.addOrUpdatePolicy(dropPolicy);
    root.put(POLICY_ID, dropPolicy.policyId().toString());
    return Response.ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PolicyService(org.onosproject.segmentrouting.policy.api.PolicyService) DropPolicy(org.onosproject.segmentrouting.policy.api.DropPolicy) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 4 with DropPolicy

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

the class PolicyDropAddCommand method doExecute.

@Override
protected void doExecute() {
    PolicyService policyService = AbstractShellCommand.get(PolicyService.class);
    PolicyId policyId = policyService.addOrUpdatePolicy(new DropPolicy());
    print("Policy %s has been submitted", policyId);
}
Also used : PolicyService(org.onosproject.segmentrouting.policy.api.PolicyService) DropPolicy(org.onosproject.segmentrouting.policy.api.DropPolicy) PolicyId(org.onosproject.segmentrouting.policy.api.PolicyId)

Example 5 with DropPolicy

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

Aggregations

DropPolicy (org.onosproject.segmentrouting.policy.api.DropPolicy)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 PolicyService (org.onosproject.segmentrouting.policy.api.PolicyService)4 Produces (javax.ws.rs.Produces)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Policy (org.onosproject.segmentrouting.policy.api.Policy)2 PolicyType (org.onosproject.segmentrouting.policy.api.Policy.PolicyType)2 PolicyData (org.onosproject.segmentrouting.policy.api.PolicyData)2 RedirectPolicy (org.onosproject.segmentrouting.policy.api.RedirectPolicy)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Before (org.junit.Before)1 Test (org.junit.Test)1 MockCodecContext (org.onosproject.codec.impl.MockCodecContext)1 PolicyId (org.onosproject.segmentrouting.policy.api.PolicyId)1