Search in sources :

Example 11 with GroupKey

use of org.onosproject.net.group.GroupKey in project onos by opennetworkinglab.

the class GroupCodec method decode.

@Override
public Group decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    final JsonCodec<GroupBucket> groupBucketCodec = context.codec(GroupBucket.class);
    CoreService coreService = context.getService(CoreService.class);
    // parse uInt Group id from the ID field
    JsonNode idNode = json.get(ID);
    Long id = (null == idNode) ? // use GROUP_ID for the corresponding Group id if ID is not supplied
    nullIsIllegal(json.get(GROUP_ID), ID + MISSING_MEMBER_MESSAGE).asLong() : idNode.asLong();
    GroupId groupId = GroupId.valueOf(id.intValue());
    // parse uInt Group id given by caller. see the GroupDescription javadoc
    JsonNode givenGroupIdNode = json.get(GIVEN_GROUP_ID);
    // if GIVEN_GROUP_ID is not supplied, set null so the group subsystem
    // to choose the Group id (which is the value of ID indeed).
    // else, must be same with ID to show both originate from the same source
    Integer givenGroupIdInt = (null == givenGroupIdNode) ? null : new Long(json.get(GIVEN_GROUP_ID).asLong()).intValue();
    if (givenGroupIdInt != null && !givenGroupIdInt.equals(groupId.id())) {
        throw new IllegalArgumentException(GIVEN_GROUP_ID + " must be same with " + ID);
    }
    // parse group key (appCookie)
    String groupKeyStr = nullIsIllegal(json.get(APP_COOKIE), APP_COOKIE + MISSING_MEMBER_MESSAGE).asText();
    if (!groupKeyStr.startsWith("0x")) {
        throw new IllegalArgumentException("APP_COOKIE must be a hex string starts with 0x");
    }
    GroupKey groupKey = new DefaultGroupKey(HexString.fromHexString(groupKeyStr.split("0x")[1], ""));
    // parse device id
    DeviceId deviceId = DeviceId.deviceId(nullIsIllegal(json.get(DEVICE_ID), DEVICE_ID + MISSING_MEMBER_MESSAGE).asText());
    // application id
    ApplicationId appId = coreService.registerApplication(REST_APP_ID);
    // parse group type
    String type = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText();
    GroupDescription.Type groupType = null;
    switch(type) {
        case "SELECT":
            groupType = Group.Type.SELECT;
            break;
        case "INDIRECT":
            groupType = Group.Type.INDIRECT;
            break;
        case "ALL":
            groupType = Group.Type.ALL;
            break;
        case "CLONE":
            groupType = Group.Type.CLONE;
            break;
        case "FAILOVER":
            groupType = Group.Type.FAILOVER;
            break;
        default:
            nullIsIllegal(groupType, "The requested group type " + type + " is not valid");
    }
    // parse group buckets
    GroupBuckets buckets = null;
    List<GroupBucket> groupBucketList = new ArrayList<>();
    JsonNode bucketsJson = json.get(BUCKETS);
    checkNotNull(bucketsJson);
    if (bucketsJson != null) {
        IntStream.range(0, bucketsJson.size()).forEach(i -> {
            ObjectNode bucketJson = get(bucketsJson, i);
            bucketJson.put("type", type);
            groupBucketList.add(groupBucketCodec.decode(bucketJson, context));
        });
        buckets = new GroupBuckets(groupBucketList);
    }
    GroupDescription groupDescription = new DefaultGroupDescription(deviceId, groupType, buckets, groupKey, givenGroupIdInt, appId);
    return new DefaultGroup(groupId, groupDescription);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) ArrayList(java.util.ArrayList) DefaultGroup(org.onosproject.net.group.DefaultGroup) CoreService(org.onosproject.core.CoreService) JsonNode(com.fasterxml.jackson.databind.JsonNode) HexString(org.onlab.util.HexString) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupId(org.onosproject.core.GroupId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) GroupBucket(org.onosproject.net.group.GroupBucket) ApplicationId(org.onosproject.core.ApplicationId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Example 12 with GroupKey

use of org.onosproject.net.group.GroupKey in project onos by opennetworkinglab.

the class IntentManager method purge.

@Override
public void purge(Intent intent) {
    checkPermission(INTENT_WRITE);
    checkNotNull(intent, INTENT_NULL);
    IntentData data = IntentData.purge(intent);
    store.addPending(data);
    // remove associated group if there is one
    if (intent instanceof PointToPointIntent) {
        PointToPointIntent pointIntent = (PointToPointIntent) intent;
        DeviceId deviceId = pointIntent.filteredIngressPoint().connectPoint().deviceId();
        GroupKey groupKey = PointToPointIntentCompiler.makeGroupKey(intent.id());
        groupService.removeGroup(deviceId, groupKey, intent.appId());
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) IntentData(org.onosproject.net.intent.IntentData) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) GroupKey(org.onosproject.net.group.GroupKey)

Example 13 with GroupKey

use of org.onosproject.net.group.GroupKey in project onos by opennetworkinglab.

the class PointToPointIntentCompiler method updateFailoverGroup.

// Removes buckets whose treatments rely on disabled ports from the
// failover group.
private void updateFailoverGroup(PointToPointIntent pointIntent) {
    DeviceId deviceId = pointIntent.filteredIngressPoint().connectPoint().deviceId();
    GroupKey groupKey = makeGroupKey(pointIntent.id());
    Group group = waitForGroup(deviceId, groupKey);
    Iterator<GroupBucket> groupIterator = group.buckets().buckets().iterator();
    while (groupIterator.hasNext()) {
        GroupBucket bucket = groupIterator.next();
        Instruction individualInstruction = bucket.treatment().allInstructions().get(0);
        if (individualInstruction instanceof Instructions.OutputInstruction) {
            Instructions.OutputInstruction outInstruction = (Instructions.OutputInstruction) individualInstruction;
            Port port = deviceService.getPort(deviceId, outInstruction.port());
            if (port == null || !port.isEnabled()) {
                GroupBuckets removeBuckets = new GroupBuckets(Collections.singletonList(bucket));
                groupService.removeBucketsFromGroup(deviceId, groupKey, removeBuckets, groupKey, pointIntent.appId());
            }
        }
    }
}
Also used : Group(org.onosproject.net.group.Group) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) Instructions(org.onosproject.net.flow.instructions.Instructions) Instruction(org.onosproject.net.flow.instructions.Instruction) GroupBuckets(org.onosproject.net.group.GroupBuckets)

Example 14 with GroupKey

use of org.onosproject.net.group.GroupKey in project onos by opennetworkinglab.

the class OvsOfdpaPipeline method initPopVlanPuntGroup.

/**
 * Builds a indirect group contains pop_vlan and punt actions.
 * <p>
 * Using group instead of immediate action to ensure that
 * the copy of packet on the data plane is not affected by the pop vlan action.
 */
private void initPopVlanPuntGroup() {
    GroupKey groupKey = popVlanPuntGroupKey();
    TrafficTreatment bucketTreatment = DefaultTrafficTreatment.builder().popVlan().punt().build();
    GroupBucket bucket = DefaultGroupBucket.createIndirectGroupBucket(bucketTreatment);
    GroupDescription groupDesc = new DefaultGroupDescription(deviceId, GroupDescription.Type.INDIRECT, new GroupBuckets(Collections.singletonList(bucket)), groupKey, POP_VLAN_PUNT_GROUP_ID, driverId);
    groupService.addGroup(groupDesc);
    log.info("Initialized pop vlan punt group on {}", deviceId);
}
Also used : DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Example 15 with GroupKey

use of org.onosproject.net.group.GroupKey in project onos by opennetworkinglab.

the class OvsOfdpaPipeline method processDoubleVlanIdFilter.

/**
 * Internal implementation of processDoubleVlanIdFilter.
 *
 * @param portCriterion       port on device for which this filter is programmed
 * @param innerVidCriterion   inner vlan
 * @param outerVidCriterion   outer vlan
 * @param popVlan             true if outer vlan header needs to be removed
 * @param applicationId       for application programming this filter
 * @return flow rules for port-vlan filters
 */
private List<FlowRule> processDoubleVlanIdFilter(PortCriterion portCriterion, VlanIdCriterion innerVidCriterion, VlanIdCriterion outerVidCriterion, boolean popVlan, ApplicationId applicationId) {
    List<FlowRule> rules = new ArrayList<>();
    TrafficSelector.Builder outerSelector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder outerTreatment = DefaultTrafficTreatment.builder();
    TrafficSelector.Builder innerSelector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder innerTreatment = DefaultTrafficTreatment.builder();
    VlanId outerVlanId = outerVidCriterion.vlanId();
    VlanId innerVlanId = innerVidCriterion.vlanId();
    PortNumber portNumber = portCriterion.port();
    // Check arguments
    if (PortNumber.ALL.equals(portNumber) || outerVlanId.equals(VlanId.NONE) || innerVlanId.equals(VlanId.NONE)) {
        log.warn("Incomplete Filtering Objective. " + "VLAN Table cannot be programmed for {}", deviceId);
        return ImmutableList.of();
    } else {
        outerSelector.matchInPort(portNumber);
        innerSelector.matchInPort(portNumber);
        outerTreatment.transition(VLAN_1_TABLE);
        innerTreatment.transition(TMAC_TABLE);
        outerTreatment.writeMetadata(outerVlanId.toShort(), 0xFFF);
        outerSelector.matchVlanId(outerVlanId);
        innerSelector.matchVlanId(innerVlanId);
        // force recompilation
        // FIXME might be issue due tu /fff mask
        innerSelector.matchMetadata(outerVlanId.toShort());
        if (popVlan) {
            outerTreatment.popVlan();
        }
    }
    // NOTE: for double-tagged packets, restore original outer vlan
    // before sending it to the controller.
    GroupKey groupKey = popVlanPuntGroupKey();
    Group group = groupService.getGroup(deviceId, groupKey);
    if (group != null) {
        // push outer vlan and send to controller
        TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder().matchInPort(portNumber).matchVlanId(innerVlanId);
        Host host = handler().get(HostService.class).getConnectedHosts(ConnectPoint.deviceConnectPoint(deviceId + "/" + portNumber.toLong())).stream().filter(h -> h.vlan().equals(outerVlanId)).findFirst().orElse(null);
        EthType vlanType = EthType.EtherType.VLAN.ethType();
        if (host != null) {
            vlanType = host.tpid();
        }
        TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder().pushVlan(vlanType).setVlanId(outerVlanId).punt();
        rules.add(DefaultFlowRule.builder().forDevice(deviceId).withSelector(sbuilder.build()).withTreatment(tbuilder.build()).withPriority(PacketPriority.CONTROL.priorityValue()).fromApp(driverId).makePermanent().forTable(PUNT_TABLE).build());
    } else {
        log.info("popVlanPuntGroup not found in dev:{}", deviceId);
        return Collections.emptyList();
    }
    FlowRule outerRule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(outerSelector.build()).withTreatment(outerTreatment.build()).withPriority(DEFAULT_PRIORITY).fromApp(applicationId).makePermanent().forTable(VLAN_TABLE).build();
    FlowRule innerRule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(innerSelector.build()).withTreatment(innerTreatment.build()).withPriority(DEFAULT_PRIORITY).fromApp(applicationId).makePermanent().forTable(VLAN_1_TABLE).build();
    rules.add(outerRule);
    rules.add(innerRule);
    return rules;
}
Also used : NextGroup(org.onosproject.net.behaviour.NextGroup) Group(org.onosproject.net.group.Group) HostService(org.onosproject.net.host.HostService) ArrayList(java.util.ArrayList) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) Host(org.onosproject.net.Host) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) EthType(org.onlab.packet.EthType) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber) VlanId(org.onlab.packet.VlanId)

Aggregations

GroupKey (org.onosproject.net.group.GroupKey)99 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)83 GroupBuckets (org.onosproject.net.group.GroupBuckets)59 GroupBucket (org.onosproject.net.group.GroupBucket)58 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)52 Group (org.onosproject.net.group.Group)50 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)48 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)48 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)47 GroupDescription (org.onosproject.net.group.GroupDescription)46 GroupId (org.onosproject.core.GroupId)31 ArrayList (java.util.ArrayList)29 PortNumber (org.onosproject.net.PortNumber)27 DefaultGroup (org.onosproject.net.group.DefaultGroup)27 NextGroup (org.onosproject.net.behaviour.NextGroup)24 OfdpaGroupHandlerUtility.l2MulticastGroupKey (org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey)21 ArrayDeque (java.util.ArrayDeque)20 Deque (java.util.Deque)19 TrafficSelector (org.onosproject.net.flow.TrafficSelector)18 Instruction (org.onosproject.net.flow.instructions.Instruction)18