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);
}
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();
}
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();
}
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);
}
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();
}
Aggregations