/*** * Serializes Group Desc Reply * @author Naveen * @param groupDescReplies * @param jGen * @throws IOException * @throws JsonProcessingException */ public static void serializeGroupDescReply(List<OFGroupDescStatsReply> groupDescReplies, JsonGenerator jGen) throws IOException, JsonProcessingException{ OFGroupDescStatsReply groupDescReply = groupDescReplies.get(0); jGen.writeStringField("version", groupDescReply.getVersion().toString()); //return the enum name jGen.writeFieldName("groupDesc"); jGen.writeStartArray(); for(OFGroupDescStatsEntry entry : groupDescReply.getEntries()) { jGen.writeStartObject(); jGen.writeStringField("groupType",entry.getGroupType().toString()); jGen.writeStringField("groupNumber",entry.getGroup().toString()); jGen.writeFieldName("buckets"); jGen.writeStartArray(); for(OFBucket buckets : entry.getBuckets()) { jGen.writeStartObject(); jGen.writeNumberField("weight", buckets.getWeight()); jGen.writeNumberField("watchPortNumber", buckets.getWatchPort().getPortNumber()); jGen.writeStringField("watchGroup", buckets.getWatchGroup().toString()); OFActionListSerializer.serializeActions(jGen, buckets.getActions()); jGen.writeEndObject(); }//End of for loop - buckets jGen.writeEndArray();//end of buckets jGen.writeEndObject();//end of group Desc iteration }//End of for loop - GroupDescStats jGen.writeEndArray();//end of group Desc }
private OFGroupDescStatsEntry ofGroupDescStatsEntry(Group group) { List<OFBucket> ofBuckets = Lists.newArrayList(); group.buckets().buckets().forEach(groupBucket -> { ofBuckets.add(FACTORY.buildBucket() .setWeight(groupBucket.weight()) .setWatchGroup(OFGroup.of(groupBucket.watchGroup().id())) .setWatchPort(OFPort.of((int) groupBucket.watchPort().toLong())) .build() ); }); OFGroup ofGroup = OFGroup.of(group.givenGroupId()); OFGroupType ofGroupType = OFGroupType.valueOf(group.type().name()); OFGroupDescStatsEntry entry = FACTORY.buildGroupDescStatsEntry() .setGroup(ofGroup) .setGroupType(ofGroupType) .setBuckets(ofBuckets) .build(); return entry; }
private synchronized Collection<OFGroupDescStatsEntry> publishGroupDescStats(Dpid dpid, OFGroupDescStatsReply reply) { //TODO: Get rid of synchronized fullGroupDescStats.putAll(dpid, reply.getEntries()); if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { return fullGroupDescStats.removeAll(dpid); } return null; }
private void processGroupDesc(OFGroupDescStatsReply gdsr) { log.info("Sw: {} Group Desc {} in driverState {} ", getStringId(), gdsr, driverState); if (driverState == DriverState.AUDIT_GROUPS) { auditBucketToGroupIds = new ConcurrentHashMap<List<BucketInfo>, List<Integer>>(); for (OFGroupDescStatsEntry entry : gdsr.getEntries()) { int groupId = entry.getGroup().getGroupNumber(); OFGroupType groupType = entry.getGroupType(); List<OFBucket> buckets = entry.getBuckets(); List<BucketInfo> driverBuckets = new ArrayList<BucketInfo>(); for (OFBucket bucket : buckets) { driverBuckets.add(getDriverBucketFromOFBucket(bucket)); } Collections.sort(driverBuckets); List<Integer> groupIds = auditBucketToGroupIds.get(driverBuckets); if (groupIds == null) groupIds = new ArrayList<Integer>(); groupIds.add(groupId); auditBucketToGroupIds.put(driverBuckets, groupIds); ecmpGroups.put(groupId, new EcmpInfo(groupId, groupType, driverBuckets)); } log.debug("processGroupDesc: Groups that are present in " + "switch {} are {} ", getStringId(), ecmpGroups); } else { // TODO -- actually do verification } try { nextDriverState(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public OFGroupDescStatsEntryMod(OFGroupDescStatsEntry GroupStatsEntry) { this.GroupDescStatsEntry = GroupStatsEntry; }
public OFGroupDescStatsEntry getGroupDescStatsEntry() { return this.GroupDescStatsEntry; }
@Override public void serialize(OFGroupDescStatsEntryMod groupDescStatsModEntry, JsonGenerator jGen, SerializerProvider sp) throws IOException, JsonGenerationException { OFGroupDescStatsEntry groupDescStatsEntryMod = groupDescStatsModEntry.getGroupDescStatsEntry(); List<OFBucket> Buckets = groupDescStatsEntryMod.getBuckets(); jGen.writeStartObject(); jGen.writeNumberField("groupId", groupDescStatsEntryMod.getGroup().getGroupNumber()); jGen.writeStringField("groupType", groupDescStatsEntryMod.getGroupType().name()); jGen.writeArrayFieldStart("bucketsActions"); for (OFBucket bucket : Buckets){ jGen.writeStartObject(); List<OFAction> actions = bucket.getActions(); for (OFAction action : actions ){ if(action.getType().compareTo(OFActionType.SET_FIELD) == 0){ /* * TODO: 1-Need better if condition. * TODO: 2-Complete REST response. (Right now we are only sending what * SegmentRouter CLI needs). */ if (((OFActionSetField)action).getField().toString().contains("OFOxmEthSrcVer13")){ jGen.writeStringField("SET_DL_SRC", ((OFActionSetField)action).getField().getValue().toString()); } else if (((OFActionSetField)action).getField().toString().contains("OFOxmEthDstVer13")){ jGen.writeStringField("SET_DL_DST", ((OFActionSetField)action).getField().getValue().toString()); } else if (((OFActionSetField)action).getField().toString().contains("OFOxmMplsLabelVer13")){ jGen.writeNumberField("PUSH_MPLS_LABEL", Integer.decode(((OFActionSetField)action).getField().getValue().toString())); } else if (((OFActionSetField)action).getField().toString().contains("OFOxmMplsBosVer13")){ jGen.writeStringField("PUSH_MPLS_BOS", ((OFActionSetField)action).getField().getValue().toString()); } } else if(action.getType().compareTo(OFActionType.OUTPUT) == 0){ jGen.writeNumberField("OUTPUT", ((OFActionOutput)action).getPort().getPortNumber()); } else if(action.getType().compareTo(OFActionType.POP_MPLS) == 0){ jGen.writeStringField("POP_MPLS", "0x"+((OFActionPopMpls)action).getEthertype().toString()); } else if(action.getType().compareTo(OFActionType.GROUP) == 0){ ((OFActionGroup)action).getGroup().getGroupNumber(); jGen.writeNumberField("goToGroup", ((OFActionGroup)action).getGroup().getGroupNumber()); } else if(action.getType().compareTo(OFActionType.COPY_TTL_IN) == 0 || action.getType().compareTo(OFActionType.COPY_TTL_OUT) == 0 || action.getType().compareTo(OFActionType.DEC_MPLS_TTL) == 0 || action.getType().compareTo(OFActionType.DEC_NW_TTL) == 0 || action.getType().compareTo(OFActionType.POP_PBB) == 0 || action.getType().compareTo(OFActionType.POP_VLAN) == 0){ jGen.writeStringField(action.getType().name(), "True"); } } jGen.writeEndObject(); } jGen.writeEndArray(); jGen.writeEndObject(); }