Search in sources :

Example 6 with GroupId

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

the class OvsdbTunnelProviderTest method testTunnelAdded.

@Test
public void testTunnelAdded() {
    TunnelEndPoint src = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf("192.168.1.1"));
    TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf("192.168.1.3"));
    SparseAnnotations annotations = DefaultAnnotations.builder().set("bandwidth", "1024").build();
    List<Link> links = new ArrayList<Link>();
    links.add(link);
    TunnelDescription tunnel = new DefaultTunnelDescription(TunnelId.valueOf("1234"), src, dst, Tunnel.Type.VXLAN, new GroupId(0), this.provider.id(), TunnelName.tunnelName("tunnel12"), new DefaultPath(this.provider.id(), links, ScalarWeight.toWeight(0.3)), annotations);
    provider.tunnelAdded(tunnel);
    assertEquals(1, providerService.tunnelSet.size());
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) TunnelEndPoint(org.onosproject.incubator.net.tunnel.TunnelEndPoint) IpTunnelEndPoint(org.onosproject.incubator.net.tunnel.IpTunnelEndPoint) ArrayList(java.util.ArrayList) DefaultTunnelDescription(org.onosproject.incubator.net.tunnel.DefaultTunnelDescription) TunnelDescription(org.onosproject.incubator.net.tunnel.TunnelDescription) DefaultTunnelDescription(org.onosproject.incubator.net.tunnel.DefaultTunnelDescription) DefaultPath(org.onosproject.net.DefaultPath) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink) GroupId(org.onosproject.core.GroupId) Test(org.junit.Test)

Example 7 with GroupId

use of org.onosproject.core.GroupId 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 8 with GroupId

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

the class GroupBucketCodec method decode.

@Override
public GroupBucket decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    // build traffic treatment
    ObjectNode treatmentJson = get(json, TREATMENT);
    TrafficTreatment trafficTreatment = null;
    if (treatmentJson != null) {
        JsonCodec<TrafficTreatment> treatmentCodec = context.codec(TrafficTreatment.class);
        trafficTreatment = treatmentCodec.decode(treatmentJson, context);
    }
    // parse group type
    String type = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText();
    GroupBucket groupBucket = null;
    switch(type) {
        case "SELECT":
            // parse weight
            int weightInt = nullIsIllegal(json.get(WEIGHT), WEIGHT + MISSING_MEMBER_MESSAGE).asInt();
            groupBucket = DefaultGroupBucket.createSelectGroupBucket(trafficTreatment, (short) weightInt);
            break;
        case "INDIRECT":
            groupBucket = DefaultGroupBucket.createIndirectGroupBucket(trafficTreatment);
            break;
        case "ALL":
            groupBucket = DefaultGroupBucket.createAllGroupBucket(trafficTreatment);
            break;
        case "FAILOVER":
            // parse watchPort
            PortNumber watchPort = PortNumber.portNumber(nullIsIllegal(json.get(WATCH_PORT), WATCH_PORT + MISSING_MEMBER_MESSAGE).asText());
            // parse watchGroup
            int groupIdInt = nullIsIllegal(json.get(WATCH_GROUP), WATCH_GROUP + MISSING_MEMBER_MESSAGE).asInt();
            GroupId watchGroup = new GroupId((short) groupIdInt);
            groupBucket = DefaultGroupBucket.createFailoverGroupBucket(trafficTreatment, watchPort, watchGroup);
            break;
        default:
            DefaultGroupBucket.createAllGroupBucket(trafficTreatment);
    }
    return groupBucket;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PortNumber(org.onosproject.net.PortNumber) GroupId(org.onosproject.core.GroupId)

Example 9 with GroupId

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

the class NullGroupProvider method groupAdd.

private void groupAdd(DeviceId deviceId, GroupOperation go) {
    GroupId gid = go.groupId();
    DefaultGroup group = new DefaultGroup(gid, deviceId, go.groupType(), go.buckets());
    group.setState(Group.GroupState.ADDED);
    groupTables.get(deviceId).put(gid, group);
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupId(org.onosproject.core.GroupId)

Example 10 with GroupId

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

the class OvsOfdpaPipeline method buildPuntTableRule.

/**
 * Creates punt table entry that matches IN_PORT and VLAN_VID and points to
 * a group that pop vlan and punt.
 *
 * @param portNumber port number
 * @param assignedVlan internally assigned vlan id
 * @return punt table flow rule
 */
private FlowRule buildPuntTableRule(PortNumber portNumber, VlanId assignedVlan) {
    TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder().matchInPort(portNumber).matchVlanId(assignedVlan);
    TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder().group(new GroupId(POP_VLAN_PUNT_GROUP_ID));
    return DefaultFlowRule.builder().forDevice(deviceId).withSelector(sbuilder.build()).withTreatment(tbuilder.build()).withPriority(PacketPriority.CONTROL.priorityValue()).fromApp(driverId).makePermanent().forTable(PUNT_TABLE).build();
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupId(org.onosproject.core.GroupId)

Aggregations

GroupId (org.onosproject.core.GroupId)59 GroupBucket (org.onosproject.net.group.GroupBucket)30 GroupKey (org.onosproject.net.group.GroupKey)29 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)26 GroupBuckets (org.onosproject.net.group.GroupBuckets)26 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)25 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)24 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)21 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)19 GroupDescription (org.onosproject.net.group.GroupDescription)19 DefaultGroup (org.onosproject.net.group.DefaultGroup)18 Group (org.onosproject.net.group.Group)17 GroupEvent (org.onosproject.net.group.GroupEvent)12 ArrayList (java.util.ArrayList)11 PortNumber (org.onosproject.net.PortNumber)11 Instruction (org.onosproject.net.flow.instructions.Instruction)10 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)10 StoredGroupEntry (org.onosproject.net.group.StoredGroupEntry)10 OfdpaGroupHandlerUtility.l2MulticastGroupKey (org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey)9 MacAddress (org.onlab.packet.MacAddress)8