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