org.onosproject.net.flowobjective.NextObjective Java Examples

The following examples show how to use org.onosproject.net.flowobjective.NextObjective. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultSingleTablePipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Gets traffic treatment from a next objective.
 * Merge traffic treatments from next objective if the next objective is
 * BROADCAST type and contains multiple traffic treatments.
 * Returns first treatment from next objective if the next objective is
 * SIMPLE type and it contains only one treatment.
 *
 * @param nextObjective the next objective
 * @return the treatment from next objective; null if not supported
 */
private TrafficTreatment getTreatment(NextObjective nextObjective) {
    Collection<TrafficTreatment> treatments = nextObjective.next();
    switch (nextObjective.type()) {
        case SIMPLE:
            if (treatments.size() != 1) {
                log.error("Next Objectives of type SIMPLE should have only " +
                                  "one traffic treatment. NexObjective: {}",
                          nextObjective.toString());
                return null;
            }
            return treatments.iterator().next();
        case BROADCAST:
            TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
            treatments.forEach(builder::addTreatment);
            return builder.build();
        default:
            log.error("Unsupported next objective type {}.", nextObjective.type());
            return null;
    }
}
 
Example #2
Source File: FibInstallerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests updating a route.
 *
 * We verify that the flowObjectiveService records the correct state and that the
 * correct flow is submitted to the flowObjectiveService.
 */
@Test
public void testRouteUpdate() {
    // Firstly add a route
    testRouteAdd();
    reset(flowObjectiveService);

    ResolvedRoute oldRoute = createRoute(PREFIX1, NEXT_HOP1, MAC1);
    ResolvedRoute route = createRoute(PREFIX1, NEXT_HOP2, MAC2);

    // Create the next objective
    NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
    flowObjectiveService.next(DEVICE_ID, nextObjective);

    // Create the flow objective
    ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
    flowObjectiveService.forward(DEVICE_ID, fwd);
    EasyMock.expectLastCall().once();
    setUpFlowObjectiveService();

    // Send in the update event
    routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, route, oldRoute));

    verify(flowObjectiveService);
}
 
Example #3
Source File: SoftRouterPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void next(NextObjective nextObjective) {
    switch (nextObjective.type()) {
        case SIMPLE:
            Collection<TrafficTreatment> treatments = nextObjective.next();
            if (treatments.size() != 1) {
                log.error("Next Objectives of type Simple should only have a "
                                  + "single Traffic Treatment. Next Objective Id:{}", nextObjective.id());
                fail(nextObjective, ObjectiveError.BADPARAMS);
                return;
            }
            processSimpleNextObjective(nextObjective);
            break;
        case HASHED:
        case BROADCAST:
        case FAILOVER:
            fail(nextObjective, ObjectiveError.UNSUPPORTED);
            log.warn("Unsupported next objective type {}", nextObjective.type());
            break;
        default:
            fail(nextObjective, ObjectiveError.UNKNOWN);
            log.warn("Unknown next objective type {}", nextObjective.type());
    }
}
 
Example #4
Source File: FibInstallerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests adding a route.
 *
 * We verify that the flowObjectiveService records the correct state and that the
 * correct flow is submitted to the flowObjectiveService.
 */
@Test
public void testRouteAdd() {
    ResolvedRoute resolvedRoute = createRoute(PREFIX1, NEXT_HOP1, MAC1);

    // Create the next objective
    NextObjective nextObjective = createNextObjective(MAC1, MAC1, SW1_ETH1.port(), VlanId.NONE, true);
    flowObjectiveService.next(DEVICE_ID, nextObjective);

    // Create the flow objective
    ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
    flowObjectiveService.forward(DEVICE_ID, fwd);
    EasyMock.expectLastCall().once();
    setUpFlowObjectiveService();

    // Send in the add event
    RouteEvent routeEvent = new RouteEvent(RouteEvent.Type.ROUTE_ADDED, resolvedRoute);
    routeListener.event(routeEvent);
    verify(flowObjectiveService);
}
 
Example #5
Source File: FlowObjectiveManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests adding a next objective.
 */
@Test
public void nextObjective() {
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    NextObjective next =
            DefaultNextObjective.builder()
                    .withId(manager.allocateNextId())
                    .addTreatment(treatment)
                    .withType(NextObjective.Type.BROADCAST)
                    .fromApp(NetTestTools.APP_ID)
                    .makePermanent()
                    .add();

    manager.next(id1, next);

    TestTools.assertAfter(RETRY_MS, () ->
            assertThat(nextObjectives, hasSize(1)));

    assertThat(forwardingObjectives, hasSize(0));
    assertThat(filteringObjectives, hasSize(0));
    assertThat(nextObjectives, hasItem("of:d1"));
}
 
Example #6
Source File: FabricPipeliner.java    From onos with Apache License 2.0 6 votes vote down vote up
private void handleNextGroup(NextObjective obj) {
    switch (obj.op()) {
        case REMOVE:
            removeNextGroup(obj);
            break;
        case ADD:
        case ADD_TO_EXISTING:
        case REMOVE_FROM_EXISTING:
        case MODIFY:
            putNextGroup(obj);
            break;
        case VERIFY:
            break;
        default:
            log.error("Unknown NextObjective operation '{}'", obj.op());
    }
}
 
Example #7
Source File: FabricPipeliner.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void next(NextObjective obj) {
    if (obj.op() == Objective.Operation.VERIFY) {
        // TODO: support VERIFY operation
        log.debug("VERIFY operation not yet supported for NextObjective, will return success");
        success(obj);
        return;
    }

    if (obj.op() == Objective.Operation.MODIFY) {
        // TODO: support MODIFY operation
        log.warn("MODIFY operation not yet supported for NextObjective, will return failure :(");
        fail(obj, ObjectiveError.UNSUPPORTED);
        return;
    }

    final ObjectiveTranslation result = nextTranslator.translate(obj);
    handleResult(obj, result);
}
 
Example #8
Source File: InOrderFlowObjectiveManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void next(NextObjective nextObjective) {
    recordObjective(nextObjective);

    // Notify delegate when the next obj is completed
    ObjectiveEvent.Type type;
    if (nextObjective.op() == Objective.Operation.ADD ||
            nextObjective.op() == Objective.Operation.ADD_TO_EXISTING) {
        type = ObjectiveEvent.Type.ADD;
    } else if (nextObjective.op() == Objective.Operation.REMOVE ||
            nextObjective.op() == Objective.Operation.REMOVE_FROM_EXISTING) {
        type = ObjectiveEvent.Type.REMOVE;
    } else {
        return;
    }
    mgr.delegate.notify(new ObjectiveEvent(type, nextObjective.id()));
}
 
Example #9
Source File: Ofdpa2GroupHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void addBucketToBroadcastGroup(NextObjective nextObj,
                                       List<Deque<GroupKey>> allActiveKeys) {
    VlanId assignedVlan = readVlanFromSelector(nextObj.meta());
    if (assignedVlan == null) {
        log.warn("VLAN ID required by broadcast next obj is missing. "
                + "Aborting add bucket to broadcast group for next:{} in dev:{}",
                nextObj.id(), deviceId);
        fail(nextObj, ObjectiveError.BADPARAMS);
        return;
    }
    List<GroupInfo> groupInfos = prepareL2InterfaceGroup(nextObj, assignedVlan);
    IpPrefix ipDst = readIpDstFromSelector(nextObj.meta());
    if (ipDst != null) {
        if (ipDst.isMulticast()) {
            addBucketToL3MulticastGroup(nextObj, allActiveKeys, groupInfos, assignedVlan);
        } else {
            log.warn("Broadcast NextObj with non-multicast IP address {}", nextObj);
            fail(nextObj, ObjectiveError.BADPARAMS);
        }
    } else {
        addBucketToL2FloodGroup(nextObj, allActiveKeys, groupInfos, assignedVlan);
    }
}
 
Example #10
Source File: NextTable.java    From onos with Apache License 2.0 6 votes vote down vote up
public List<NextObjective> updateNext(NextObjective nextObjective) {
    List<NextObjective> updates = new ArrayList<>();
    switch (nextObjective.op()) {
        case ADD:
            this.nextMap.put(nextObjective.id(), nextObjective);
            updates.add(nextObjective);
            break;
        case REMOVE:
            this.nextMap.remove(nextObjective.id());
            updates.add(nextObjective);
            break;
        default:
            break;
    }
    return updates;
}
 
Example #11
Source File: Ofdpa2GroupHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * As per the OFDPA 2.0 TTP, packets are sent out of ports by using
 * a chain of groups. The simple Next Objective passed in by the application
 * is broken up into a group chain. The following chains can be modified
 * depending on the parameters in the Next Objective.
 * 1. L2 Interface group (no chaining)
 * 2. L3 Unicast group -> L2 Interface group
 *
 * @param nextObj  the nextObjective of type SIMPLE
 */
private void modifySimpleNextObjective(NextObjective nextObj, NextGroup nextGroup) {
    TrafficTreatment treatment = nextObj.next().iterator().next();
    // determine if plain L2 or L3->L2 chain
    boolean plainL2 = true;
    for (Instruction ins : treatment.allInstructions()) {
        if (ins.type() == Instruction.Type.L2MODIFICATION) {
            L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
            if (l2ins.subtype() == L2ModificationInstruction.L2SubType.ETH_DST ||
                    l2ins.subtype() == L2ModificationInstruction.L2SubType.ETH_SRC ||
                    l2ins.subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) {
                plainL2 = false;
            }
        }
    }
    if (plainL2) {
        modifyBucketInL2Group(nextObj, nextGroup);
    } else {
        modifyBucketInL3Group(nextObj, nextGroup);
    }
    return;
}
 
Example #12
Source File: InOrderFlowObjectiveManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates next objective builder.
 *
 * @param nextId next ID
 * @param vlanId VLAN ID
 * @param ports Set of ports that is in the given VLAN ID
 *
 * @return Next objective builder
 */
private static NextObjective.Builder buildNextObjective(int nextId, VlanId vlanId, Collection<PortNumber> ports) {
    TrafficSelector metadata =
            DefaultTrafficSelector.builder().matchVlanId(vlanId).build();

    NextObjective.Builder nextObjBuilder = DefaultNextObjective
            .builder().withId(nextId)
            .withType(NextObjective.Type.BROADCAST).fromApp(APP_ID)
            .withMeta(metadata);

    ports.forEach(port -> {
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
        tBuilder.popVlan();
        tBuilder.setOutput(port);
        nextObjBuilder.addTreatment(tBuilder.build());
    });

    return nextObjBuilder;
}
 
Example #13
Source File: NextObjectiveTranslator.java    From onos with Apache License 2.0 6 votes vote down vote up
private void hashedNext(NextObjective obj,
                        ObjectiveTranslation.Builder resultBuilder)
        throws FabricPipelinerException {

    if (!capabilities.hasHashedTable()) {
        simpleNext(obj, resultBuilder, true);
        return;
    }

    // Updated result builder with hashed group.
    final int groupId = selectGroup(obj, resultBuilder);

    if (isGroupModifyOp(obj)) {
        // No changes to flow rules.
        return;
    }

    final TrafficSelector selector = nextIdSelector(obj.id());
    final TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .piTableAction(PiActionProfileGroupId.of(groupId))
            .build();

    resultBuilder.addFlowRule(flowRule(
            obj, FabricConstants.FABRIC_INGRESS_NEXT_HASHED,
            selector, treatment));
}
 
Example #14
Source File: AbstractCorsaPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    Set<GroupKey> keys = pendingGroups.asMap().keySet().stream()
            .filter(key -> groupService.getGroup(deviceId, key) != null)
            .collect(Collectors.toSet());

    keys.forEach(key -> {
        NextObjective obj = pendingGroups.getIfPresent(key);
        if (obj == null) {
            return;
        }
        pass(obj);
        pendingGroups.invalidate(key);
        log.info("Heard back from group service for group {}. "
                + "Applying pending forwarding objectives", obj.id());
        flowObjectiveStore.putNextGroup(obj.id(), new CorsaGroup(key));
    });
}
 
Example #15
Source File: Ofdpa2GroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Removes all groups in multiple possible group-chains that represent the next-obj.
 *
 * @param nextObjective the next objective to remove
 * @param next the NextGroup that represents the existing group-chain for
 *             this next objective
 */
protected void removeGroup(NextObjective nextObjective, NextGroup next) {

    List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data());

    List<GroupKey> groupKeys = allActiveKeys.stream()
            .map(Deque::getFirst).collect(Collectors.toList());
    addPendingRemoveNextObjective(nextObjective, groupKeys);

    allActiveKeys
            .forEach(groupChain -> groupChain.forEach(groupKey -> groupService
                    .removeGroup(deviceId, groupKey, nextObjective.appId())));
    flowObjectiveStore.removeNextGroup(nextObjective.id());
}
 
Example #16
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Remove simple next objective for a single port. The treatments can include
 * all outgoing actions that need to happen on the packet.
 *
 * @param portNum  the outgoing port on the device
 * @param treatment the actions applied on the packets (should include outport)
 * @param meta optional data to pass to the driver
 */
public void removeGroupFromPort(PortNumber portNum, TrafficTreatment treatment,
                                TrafficSelector meta) {
    PortNextObjectiveStoreKey key = new PortNextObjectiveStoreKey(
            deviceId, portNum, treatment, meta);
    Integer nextId = portNextObjStore.get(key);

    NextObjective.Builder nextObjBuilder = DefaultNextObjective
            .builder().withId(nextId)
            .withType(NextObjective.Type.SIMPLE)
            .addTreatment(treatment)
            .fromApp(appId)
            .withMeta(meta);

    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) ->
                    log.info("removeGroupFromPort installed "
                                      + "NextObj {} on {}", nextId, deviceId),
            (objective, error) -> {
                log.warn("removeGroupFromPort failed to install NextObj {} on {}: {}", nextId, deviceId, error);
                srManager.invalidateNextObj(objective.id());
            }
    );
    NextObjective nextObj = nextObjBuilder.remove(context);
    flowObjectiveService.next(deviceId, nextObj);
    log.info("removeGroupFromPort: Submitted next objective {} in device {} "
                      + "for port {}", nextId, deviceId, portNum);

    portNextObjStore.remove(key);
}
 
Example #17
Source File: LinkCollectionIntentFlowObjectiveCompilerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private void checkNext(NextObjective nextObjective,
                       NextObjective.Type type,
                       Collection<TrafficTreatment> next,
                       TrafficSelector meta,
                       Objective.Operation op) {
    assertThat(nextObjective.type(), is(type));
    assertThat(nextObjective.next().size(), is(next.size()));
    assertThat(nextObjective.next().containsAll(next), is(true));
    assertThat(nextObjective.meta(), is(meta));
    assertThat(nextObjective.op(), is(op));
}
 
Example #18
Source File: CentecV350Pipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void init(DeviceId deviceId, PipelinerContext context) {
    this.serviceDirectory = context.directory();
    this.deviceId = deviceId;

    pendingGroups = CacheBuilder.newBuilder()
            .expireAfterWrite(20, TimeUnit.SECONDS)
            .removalListener((RemovalNotification<GroupKey, NextObjective> notification) -> {
                if (notification.getCause() == RemovalCause.EXPIRED) {
                    fail(notification.getValue(), ObjectiveError.GROUPINSTALLATIONFAILED);
                }
            }).build();

    groupChecker.scheduleAtFixedRate(new GroupChecker(), 0, 500, TimeUnit.MILLISECONDS);

    coreService = serviceDirectory.get(CoreService.class);
    flowRuleService = serviceDirectory.get(FlowRuleService.class);
    groupService = serviceDirectory.get(GroupService.class);
    flowObjectiveStore = context.store();

    groupService.addListener(new InnerGroupListener());

    appId = coreService.registerApplication(
            "org.onosproject.driver.CentecV350Pipeline");

    initializePipeline();
}
 
Example #19
Source File: NextObjectiveCodecTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #20
Source File: OltPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void init(DeviceId deviceId, PipelinerContext context) {
    log.debug("Initiate OLT pipeline");
    this.serviceDirectory = context.directory();
    this.deviceId = deviceId;

    flowRuleService = serviceDirectory.get(FlowRuleService.class);
    coreService = serviceDirectory.get(CoreService.class);
    groupService = serviceDirectory.get(GroupService.class);
    flowObjectiveStore = context.store();
    storageService = serviceDirectory.get(StorageService.class);

    appId = coreService.registerApplication(
            "org.onosproject.driver.OLTPipeline");


    pendingGroups = CacheBuilder.newBuilder()
            .expireAfterWrite(20, TimeUnit.SECONDS)
            .removalListener((RemovalNotification<GroupKey, NextObjective> notification) -> {
                if (notification.getCause() == RemovalCause.EXPIRED) {
                    fail(notification.getValue(), ObjectiveError.GROUPINSTALLATIONFAILED);
                }
            }).build();

    groupService.addListener(new InnerGroupListener());

}
 
Example #21
Source File: SpringOpenTTP.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    Set<GroupKey> keys = pendingGroups
            .asMap()
            .keySet()
            .stream()
            .filter(key -> groupService.getGroup(deviceId, key) != null)
            .collect(Collectors.toSet());

    keys.forEach(key -> {
        NextObjective obj = pendingGroups
                .getIfPresent(key);
        if (obj == null) {
            return;
        }
        log.debug("Group verified: dev:{} gid:{} <<->> nextId:{}",
                deviceId,
                groupService.getGroup(deviceId, key).id(),
                obj.id());
        pass(obj);
        pendingGroups.invalidate(key);
        flowObjectiveStore.putNextGroup(
                obj.id(),
                new SpringOpenGroup(key, null));
    });

    if (!pendingGroups.asMap().isEmpty()) {
        // Periodically execute only if entry remains in pendingGroups.
        // Iterating pendingGroups trigger cleanUp and expiration,
        // which will eventually empty the pendingGroups.
        verifyPendingGroupLater();
    }
}
 
Example #22
Source File: SpringOpenTTP.java    From onos with Apache License 2.0 5 votes vote down vote up
private void removeBucketFromGroup(NextObjective nextObjective) {
    log.debug("removeBucketFromGroup in {}: for next objective id {}",
              deviceId, nextObjective.id());
    NextGroup nextGroup = flowObjectiveStore.getNextGroup(nextObjective.id());
    if (nextGroup != null) {
        Collection<TrafficTreatment> treatments = nextObjective.next();
        TrafficTreatment treatment = treatments.iterator().next();
        final GroupKey key = new DefaultGroupKey(
                appKryo.serialize(nextObjective
                        .id()));
        Group group = groupService.getGroup(deviceId, key);
        if (group == null) {
            log.warn("Group is not found in {} for {}", deviceId, key);
            return;
        }
        GroupBucket bucket;
        if (group.type() == GroupDescription.Type.INDIRECT) {
            bucket = DefaultGroupBucket.createIndirectGroupBucket(treatment);
        } else if (group.type() == GroupDescription.Type.SELECT) {
            bucket = DefaultGroupBucket.createSelectGroupBucket(treatment);
        } else if (group.type() == GroupDescription.Type.ALL) {
            bucket = DefaultGroupBucket.createAllGroupBucket(treatment);
        } else {
            log.warn("Unsupported Group type {}", group.type());
            return;
        }
        GroupBuckets removeBuckets = new GroupBuckets(Collections.singletonList(bucket));
        log.debug("Removing buckets from group id {} of next objective id {} in device {}",
                  group.id(), nextObjective.id(), deviceId);
        groupService.removeBucketsFromGroup(deviceId, key, removeBuckets, key, appId);
    }
}
 
Example #23
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Removes simple next objective for a single port.
 *
 * @param deviceId device id that has the port to deal with
 * @param portNum the outgoing port on the device
 * @param vlanId vlan id associated with the port
 * @param popVlan true if POP_VLAN action is applied on the packets, false otherwise
 */
public void removePortNextObjective(DeviceId deviceId, PortNumber portNum, VlanId vlanId, boolean popVlan) {
    TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder();
    mbuilder.matchVlanId(vlanId);

    TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
    tbuilder.immediate().setOutput(portNum);
    if (popVlan) {
        tbuilder.immediate().popVlan();
    }

    int portNextObjId = srManager.getPortNextObjectiveId(deviceId, portNum,
                                                         tbuilder.build(), mbuilder.build(), false);

    PortNextObjectiveStoreKey key = new PortNextObjectiveStoreKey(
            deviceId, portNum, tbuilder.build(), mbuilder.build());
    if (portNextObjId != -1 && portNextObjStore.containsKey(key)) {
        NextObjective.Builder nextObjBuilder = DefaultNextObjective
                .builder().withId(portNextObjId)
                .withType(NextObjective.Type.SIMPLE).fromApp(appId);
        ObjectiveContext context = new DefaultObjectiveContext(
                (objective) -> log.debug("removePortNextObjective removes NextObj {} on {}",
                                         portNextObjId, deviceId),
                (objective, error) -> {
                    log.warn("removePortNextObjective failed to remove NextObj {} on {}: {}",
                            portNextObjId, deviceId, error);
                    srManager.invalidateNextObj(objective.id());
                });
        NextObjective nextObjective = nextObjBuilder.remove(context);
        log.info("**removePortNextObjective: Submitted "
                         + "next objective {} in device {}",
                 portNextObjId, deviceId);
        flowObjectiveService.next(deviceId, nextObjective);

        portNextObjStore.remove(key);
    }
}
 
Example #24
Source File: NextObjectiveTranslator.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectiveTranslation doTranslate(NextObjective obj)
        throws FabricPipelinerException {

    final ObjectiveTranslation.Builder resultBuilder =
            ObjectiveTranslation.builder();

    switch (obj.type()) {
        case SIMPLE:
            simpleNext(obj, resultBuilder, false);
            break;
        case HASHED:
            hashedNext(obj, resultBuilder);
            break;
        case BROADCAST:
            if (isXconnect(obj)) {
                xconnectNext(obj, resultBuilder);
            } else {
                multicastNext(obj, resultBuilder);
            }
            break;
        default:
            log.warn("Unsupported NextObjective type '{}'", obj);
            return ObjectiveTranslation.ofError(ObjectiveError.UNSUPPORTED);
    }

    if (!isGroupModifyOp(obj)) {
        // Generate next VLAN rules.
        nextVlan(obj, resultBuilder);
    }

    return resultBuilder.build();
}
 
Example #25
Source File: NextObjectiveTranslator.java    From onos with Apache License 2.0 5 votes vote down vote up
private void simpleNext(NextObjective obj,
                        ObjectiveTranslation.Builder resultBuilder,
                        boolean forceSimple)
        throws FabricPipelinerException {

    if (capabilities.hasHashedTable()) {
        // Use hashed table when possible.
        hashedNext(obj, resultBuilder);
        return;
    }

    if (obj.nextTreatments().isEmpty()) {
        // Do nothing.
        return;
    } else if (!forceSimple && obj.nextTreatments().size() != 1) {
        throw new FabricPipelinerException(format(
                "SIMPLE NextObjective should contain only 1 treatment, found %d",
                obj.nextTreatments().size()), ObjectiveError.BADPARAMS);
    }

    final TrafficSelector selector = nextIdSelector(obj.id());

    final List<DefaultNextTreatment> treatments = defaultNextTreatments(
            obj.nextTreatments(), true);

    if (forceSimple && treatments.size() > 1) {
        log.warn("Forcing SIMPLE behavior for NextObjective with {} treatments []",
                 treatments.size(), obj);
    }

    // If not forcing, we are essentially extracting the only available treatment.
    final TrafficTreatment treatment = defaultNextTreatments(
            obj.nextTreatments(), true).get(0).treatment();

    resultBuilder.addFlowRule(flowRule(
            obj, FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE,
            selector, treatment));

    handleEgress(obj, treatment, resultBuilder, false);
}
 
Example #26
Source File: LinkCollectionIntentFlowObjectiveCompiler.java    From onos with Apache License 2.0 5 votes vote down vote up
private List<Objective> createBroadcastObjective(ForwardingInstructions instructions,
                                                 Set<TrafficTreatment> treatmentsWithDifferentPort,
                                                 LinkCollectionIntent intent) {
    List<Objective> objectives = Lists.newArrayList();
    ForwardingObjective forwardingObjective;
    NextObjective nextObjective;

    Integer nextId = flowObjectiveService.allocateNextId();

    forwardingObjective = buildForwardingObjective(instructions.selector(),
                                                   nextId, intent.priority());

    DefaultNextObjective.Builder nxBuilder = DefaultNextObjective.builder();
    nxBuilder.withId(nextId)
            .withMeta(instructions.selector())
            .withType(NextObjective.Type.BROADCAST)
            .fromApp(appId)
            .withPriority(intent.priority())
            .makePermanent();

    treatmentsWithDifferentPort.forEach(nxBuilder::addTreatment);
    nextObjective = nxBuilder.add();

    objectives.add(forwardingObjective);
    objectives.add(nextObjective);

    return objectives;
}
 
Example #27
Source File: NextTable.java    From onos with Apache License 2.0 5 votes vote down vote up
public List<NextObjective> updateNext(List<NextObjective> nextObjectives) {
    List<NextObjective> updates = new ArrayList<>();
    for (NextObjective nextObjective : nextObjectives) {
        updates.addAll(this.updateNext(nextObjective));
    }
    return updates;
}
 
Example #28
Source File: Ofdpa2GroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Modify buckets in the L2 interface group.
 *
 * @param nextObjective a next objective that contains information for the
 *                      buckets to be modified in the group
 * @param next the representation of the existing group-chains for this next
 *             objective, from which the innermost group buckets to remove are determined
 */

protected void modifyBucketInL2Group(NextObjective nextObjective, NextGroup next) {

    VlanId assignedVlan = readVlanFromSelector(nextObjective.meta());
    if (assignedVlan == null) {
        log.warn("VLAN ID required by simple next obj is missing. Abort.");
        fail(nextObjective, ObjectiveError.BADPARAMS);
        return;
    }

    List<GroupInfo> groupInfos = prepareL2InterfaceGroup(nextObjective, assignedVlan);

    // There is only one L2 interface group in this case
    GroupDescription l2InterfaceGroupDesc = groupInfos.get(0).innerMostGroupDesc();

    // Replace group bucket for L2 interface group
    groupService.setBucketsForGroup(deviceId,
                                    l2InterfaceGroupDesc.appCookie(),
                                    l2InterfaceGroupDesc.buckets(),
                                    l2InterfaceGroupDesc.appCookie(),
                                    l2InterfaceGroupDesc.appId());

    // update store - synchronize access as there may be multiple threads
    // trying to remove buckets from the same group, each with its own
    // potentially stale copy of allActiveKeys
    synchronized (flowObjectiveStore) {
        // NOTE: The groupKey is computed by deviceId, VLAN and portNum. It remains the same when we modify L2IG.
        //       Therefore we use the same groupKey of the existing group.
        List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data());
        flowObjectiveStore.putNextGroup(nextObjective.id(),
                                        new OfdpaNextGroup(allActiveKeys,
                                                           nextObjective));
    }

}
 
Example #29
Source File: VirtualNetworkFlowObjectiveManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void next(NextObjective nextObjective) {

    pendingNext.put(nextObjective.id(), nextObjective);
    flowObjectiveStore.putNextGroup(nextObjective.id(),
                                    new SingleGroup(
                                            new DefaultGroupKey(
                                                    appKryo.serialize(nextObjective.id()))));
    nextObjective.context().ifPresent(context -> context.onSuccess(nextObjective));
}
 
Example #30
Source File: AbstractCorsaPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void next(NextObjective nextObjective) {
    switch (nextObjective.type()) {
        case SIMPLE:
            Collection<TrafficTreatment> treatments = nextObjective.next();
            if (treatments.size() == 1) {
                TrafficTreatment treatment = treatments.iterator().next();
                CorsaTrafficTreatment corsaTreatment = processNextTreatment(treatment);
                final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
                if (corsaTreatment.type() == CorsaTrafficTreatmentType.GROUP) {
                    GroupBucket bucket = DefaultGroupBucket.createIndirectGroupBucket(corsaTreatment.treatment());
                    GroupBuckets buckets = new GroupBuckets(Collections.singletonList(bucket));
                    // group id == null, let group service determine group id
                    GroupDescription groupDescription = new DefaultGroupDescription(deviceId,
                                                                                    GroupDescription.Type.INDIRECT,
                                                                                    buckets,
                                                                                    key,
                                                                                    null,
                                                                                    nextObjective.appId());
                    groupService.addGroup(groupDescription);
                    pendingGroups.put(key, nextObjective);
                } else if (corsaTreatment.type() == CorsaTrafficTreatmentType.ACTIONS) {
                    pendingNext.put(nextObjective.id(), nextObjective);
                    flowObjectiveStore.putNextGroup(nextObjective.id(), new CorsaGroup(key));
                    nextObjective.context().ifPresent(context -> context.onSuccess(nextObjective));
                }
            }
            break;
        case HASHED:
        case BROADCAST:
        case FAILOVER:
            fail(nextObjective, ObjectiveError.UNSUPPORTED);
            log.warn("Unsupported next objective type {}", nextObjective.type());
            break;
        default:
            fail(nextObjective, ObjectiveError.UNKNOWN);
            log.warn("Unknown next objective type {}", nextObjective.type());
    }

}