Search in sources :

Example 11 with DefaultApplicationId

use of org.onosproject.core.DefaultApplicationId in project onos by opennetworkinglab.

the class FilteringObjectiveCodecTest method testFilteringObjectiveDecode.

/**
 * Test decoding of a FilteringObjective object.
 */
@Test
public void testFilteringObjectiveDecode() throws IOException {
    ApplicationId appId = new DefaultApplicationId(0, SAMPLE_APP_ID);
    expect(mockCoreService.registerApplication(SAMPLE_APP_ID)).andReturn(appId).anyTimes();
    replay(mockCoreService);
    FilteringObjective filteringObjective = getFilteringObjective("FilteringObjective.json");
    assertThat(filteringObjective.type(), is(FilteringObjective.Type.PERMIT));
    assertThat(filteringObjective.priority(), is(60));
    assertThat(filteringObjective.timeout(), is(1));
    assertThat(filteringObjective.op(), is(FilteringObjective.Operation.ADD));
    assertThat(filteringObjective.permanent(), is(false));
}
Also used : DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) FilteringObjectiveJsonMatcher.matchesFilteringObjective(org.onosproject.codec.impl.FilteringObjectiveJsonMatcher.matchesFilteringObjective) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) Test(org.junit.Test)

Example 12 with DefaultApplicationId

use of org.onosproject.core.DefaultApplicationId in project onos by opennetworkinglab.

the class ApplicationIdCodecTest method testApplicationIdEncode.

/**
 * Tests encoding of an application id object.
 */
@Test
public void testApplicationIdEncode() {
    int id = 1;
    String name = "org.onosproject.foo";
    ApplicationId appId = new DefaultApplicationId(id, name);
    ObjectNode applicationIdJson = applicationIdCodec.encode(appId, context);
    assertThat(applicationIdJson, ApplicationIdJsonMatcher.matchesApplicationId(appId));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) Test(org.junit.Test)

Example 13 with DefaultApplicationId

use of org.onosproject.core.DefaultApplicationId in project onos by opennetworkinglab.

the class NextObjectiveCodecTest method testNextObjectiveDecode.

/**
 * Test decoding of a NextObjective object.
 */
@Test
public void testNextObjectiveDecode() throws IOException {
    ApplicationId appId = new DefaultApplicationId(0, SAMPLE_APP_ID);
    expect(mockCoreService.registerApplication(SAMPLE_APP_ID)).andReturn(appId).anyTimes();
    replay(mockCoreService);
    NextObjective nextObjective = getNextObjective("NextObjective.json");
    assertThat(nextObjective.type(), is(NextObjective.Type.FAILOVER));
    assertThat(nextObjective.op(), is(NextObjective.Operation.ADD));
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) NextObjectiveJsonMatcher.matchesNextObjective(org.onosproject.codec.impl.NextObjectiveJsonMatcher.matchesNextObjective) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) Test(org.junit.Test)

Example 14 with DefaultApplicationId

use of org.onosproject.core.DefaultApplicationId in project onos by opennetworkinglab.

the class PiFlowRuleTranslatorImplTest method testTranslateFlowRules.

@Test
public void testTranslateFlowRules() throws Exception {
    ApplicationId appId = new DefaultApplicationId(1, "test");
    MacAddress ethDstMac = MacAddress.valueOf(random.nextLong());
    MacAddress ethSrcMac = MacAddress.valueOf(random.nextLong());
    short ethType = (short) (0x0000FFFF & random.nextInt());
    short outPort = (short) random.nextInt(65);
    short inPort = (short) random.nextInt(65);
    int timeout = random.nextInt(100);
    int priority = random.nextInt(100);
    TrafficSelector matchInPort1 = DefaultTrafficSelector.builder().matchInPort(PortNumber.portNumber(inPort)).matchEthDst(ethDstMac).matchEthSrc(ethSrcMac).matchEthType(ethType).build();
    TrafficSelector emptySelector = DefaultTrafficSelector.builder().build();
    TrafficTreatment outPort2 = DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(outPort)).build();
    FlowRule rule1 = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(INGRESS_TABLE0_CONTROL_TABLE0).fromApp(appId).withSelector(matchInPort1).withTreatment(outPort2).makeTemporary(timeout).withPriority(priority).build();
    FlowRule rule2 = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(INGRESS_TABLE0_CONTROL_TABLE0).fromApp(appId).withSelector(matchInPort1).withTreatment(outPort2).makeTemporary(timeout).withPriority(priority).build();
    FlowRule defActionRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(INGRESS_TABLE0_CONTROL_TABLE0).fromApp(appId).withSelector(emptySelector).withTreatment(outPort2).makeTemporary(timeout).withPriority(priority).build();
    PiTableEntry entry1 = PiFlowRuleTranslatorImpl.translate(rule1, pipeconf, null);
    PiTableEntry entry2 = PiFlowRuleTranslatorImpl.translate(rule2, pipeconf, null);
    PiTableEntry defActionEntry = PiFlowRuleTranslatorImpl.translate(defActionRule, pipeconf, null);
    // check equality, i.e. same rules must produce same entries
    new EqualsTester().addEqualityGroup(rule1, rule2).addEqualityGroup(entry1, entry2).testEquals();
    // parse values stored in entry1
    PiTernaryFieldMatch inPortParam = (PiTernaryFieldMatch) entry1.matchKey().fieldMatch(HDR_STANDARD_METADATA_INGRESS_PORT).get();
    PiTernaryFieldMatch ethDstParam = (PiTernaryFieldMatch) entry1.matchKey().fieldMatch(HDR_HDR_ETHERNET_DST_ADDR).get();
    PiTernaryFieldMatch ethSrcParam = (PiTernaryFieldMatch) entry1.matchKey().fieldMatch(HDR_HDR_ETHERNET_SRC_ADDR).get();
    PiTernaryFieldMatch ethTypeParam = (PiTernaryFieldMatch) entry1.matchKey().fieldMatch(HDR_HDR_ETHERNET_ETHER_TYPE).get();
    Optional<Double> expectedTimeout = pipeconf.pipelineModel().table(INGRESS_TABLE0_CONTROL_TABLE0).get().supportsAging() ? Optional.of((double) rule1.timeout()) : Optional.empty();
    // check that values stored in entry are the same used for the flow rule
    assertThat("Incorrect inPort match param value", inPortParam.value().asReadOnlyBuffer().getShort(), is(equalTo(inPort)));
    assertThat("Incorrect inPort match param mask", inPortParam.mask().asReadOnlyBuffer().getShort(), is(equalTo(IN_PORT_MASK)));
    assertThat("Incorrect ethDestMac match param value", ethDstParam.value().asArray(), is(equalTo(ethDstMac.toBytes())));
    assertThat("Incorrect ethDestMac match param mask", ethDstParam.mask().asArray(), is(equalTo(MacAddress.BROADCAST.toBytes())));
    assertThat("Incorrect ethSrcMac match param value", ethSrcParam.value().asArray(), is(equalTo(ethSrcMac.toBytes())));
    assertThat("Incorrect ethSrcMac match param mask", ethSrcParam.mask().asArray(), is(equalTo(MacAddress.BROADCAST.toBytes())));
    assertThat("Incorrect ethType match param value", ethTypeParam.value().asReadOnlyBuffer().getShort(), is(equalTo(ethType)));
    assertThat("Incorrect ethType match param mask", ethTypeParam.mask().asReadOnlyBuffer().getShort(), is(equalTo(ETH_TYPE_MASK)));
    // FIXME: re-enable when P4Runtime priority handling will be moved out of transltion service
    // see PiFlowRuleTranslatorImpl
    // assertThat("Incorrect priority value",
    // entry1.priority().get(), is(equalTo(MAX_PI_PRIORITY - rule1.priority())));
    assertThat("Incorrect timeout value", entry1.timeout(), is(equalTo(expectedTimeout)));
    assertThat("Match key should be empty", defActionEntry.matchKey(), is(equalTo(PiMatchKey.EMPTY)));
    assertThat("Priority should not be set", !defActionEntry.priority().isPresent());
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) PiTernaryFieldMatch(org.onosproject.net.pi.runtime.PiTernaryFieldMatch) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) PiTableEntry(org.onosproject.net.pi.runtime.PiTableEntry) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) Test(org.junit.Test)

Example 15 with DefaultApplicationId

use of org.onosproject.core.DefaultApplicationId in project onos by opennetworkinglab.

the class ImrWebResource method getMonitoredIntents.

/**
 * Get the list of monitored intents of a specific application.
 * Shows for each intent key the related end points (as inElements and OutElements).
 *
 * @onos.rsModel monitoredIntentsGet
 * @param id Application ID
 * @param name Application Name
 * @return 200 OK
 */
@GET
@Path("monitoredIntents/{id}/{name}")
@Produces(MediaType.APPLICATION_JSON)
public Response getMonitoredIntents(@PathParam("id") short id, @PathParam("name") String name) {
    imrService = get(IntentMonitorAndRerouteService.class);
    ApplicationId appId = new DefaultApplicationId(id, name);
    ArrayNode jsonMonitoredIntents = getJsonMonitoredIntents(imrService.getMonitoredIntents(appId));
    ObjectNode result = mapper.createObjectNode();
    result.putArray(ROOT_FIELD_MONITORED_INTENTS).addAll(jsonMonitoredIntents);
    return ok(result).build();
}
Also used : IntentMonitorAndRerouteService(org.onosproject.imr.IntentMonitorAndRerouteService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

DefaultApplicationId (org.onosproject.core.DefaultApplicationId)28 ApplicationId (org.onosproject.core.ApplicationId)19 Test (org.junit.Test)12 IntentMonitorAndRerouteService (org.onosproject.imr.IntentMonitorAndRerouteService)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 WebTarget (javax.ws.rs.client.WebTarget)3 Response (javax.ws.rs.core.Response)3 Before (org.junit.Before)3 TunnelService (org.onosproject.incubator.net.tunnel.TunnelService)3 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)3 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)3 FlowRule (org.onosproject.net.flow.FlowRule)3 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)3 EqualsTester (com.google.common.testing.EqualsTester)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 DefaultOpticalTunnelEndPoint (org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint)2