use of org.openkilda.messaging.info.rule.GroupEntry in project open-kilda by telstra.
the class OfFlowStatsMapperTest method testFlowGroupEntry.
@Test
public void testFlowGroupEntry() {
OFGroupDescStatsEntry entry = buildFlowGroupEntry();
GroupEntry result = OfFlowStatsMapper.INSTANCE.toFlowGroupEntry(entry);
assertEquals(entry.getGroup().getGroupNumber(), result.getGroupId());
assertEquals(entry.getGroupType().toString(), result.getGroupType());
assertEquals(entry.getBuckets().size(), result.getBuckets().size());
GroupBucket firstBucket = result.getBuckets().get(0);
assertEquals("12", firstBucket.getApplyActions().getFlowOutput());
GroupBucket secondBucket = result.getBuckets().get(1);
assertEquals(EthType.VLAN_FRAME.toString(), secondBucket.getApplyActions().getPushVlan());
assertEquals("vlan_vid", secondBucket.getApplyActions().getSetFieldActions().get(0).getFieldName());
assertEquals("12", secondBucket.getApplyActions().getSetFieldActions().get(0).getFieldValue());
assertEquals("1", secondBucket.getApplyActions().getFlowOutput());
}
use of org.openkilda.messaging.info.rule.GroupEntry in project open-kilda by telstra.
the class YFlowSwitchFlowEntriesBuilder method getGroupEntries.
/**
* Construct a set of {@link GroupEntry} that corresponds to the builder's y-flow.
*/
public Map<SwitchId, Collection<GroupEntry>> getGroupEntries() {
MultiValuedMap<SwitchId, GroupEntry> groupEntries = new ArrayListValuedHashMap<>();
yFlow.getSubFlows().forEach(subFlow -> {
Flow flow = subFlow.getFlow();
SwitchFlowEntriesBuilder builder = new SwitchFlowEntriesBuilder(flow);
builder.getSwitchGroupEntries().forEach(entries -> groupEntries.putAll(entries.getSwitchId(), entries.getGroupEntries()));
});
return groupEntries.asMap();
}
use of org.openkilda.messaging.info.rule.GroupEntry in project open-kilda by telstra.
the class YFlowValidationHubServiceTest method handleSpeakerRequests.
private void handleSpeakerRequests(YFlowValidationHubService service, String yFlowFsmKey, Map<SwitchId, Collection<FlowEntry>> flowEntries, Map<SwitchId, Collection<MeterEntry>> meterEntries, Map<SwitchId, Collection<GroupEntry>> groupEntries) {
handleSpeakerRequests(pair -> {
CommandData commandData = pair.getValue();
InfoData result = null;
if (commandData instanceof DumpRulesForFlowHsRequest) {
SwitchId switchId = ((DumpRulesForFlowHsRequest) commandData).getSwitchId();
Collection<FlowEntry> foundFlowEntries = flowEntries.get(switchId);
result = SwitchFlowEntries.builder().switchId(switchId).flowEntries(foundFlowEntries != null ? new ArrayList<>(foundFlowEntries) : emptyList()).build();
} else if (commandData instanceof DumpMetersForFlowHsRequest) {
SwitchId switchId = ((DumpMetersForFlowHsRequest) commandData).getSwitchId();
Collection<MeterEntry> foundMeterEntries = meterEntries.get(switchId);
result = SwitchMeterEntries.builder().switchId(switchId).meterEntries(foundMeterEntries != null ? new ArrayList<>(foundMeterEntries) : emptyList()).build();
} else if (commandData instanceof DumpGroupsForFlowHsRequest) {
SwitchId switchId = ((DumpGroupsForFlowHsRequest) commandData).getSwitchId();
Collection<GroupEntry> foundGroupEntries = groupEntries.get(switchId);
result = SwitchGroupEntries.builder().switchId(switchId).groupEntries(foundGroupEntries != null ? new ArrayList<>(foundGroupEntries) : emptyList()).build();
} else {
fail();
}
String flowId = pair.getKey();
service.handleAsyncResponse(yFlowFsmKey, flowId, result);
});
}
use of org.openkilda.messaging.info.rule.GroupEntry in project open-kilda by telstra.
the class RecordHandler method dumpGroupsRequest.
private void dumpGroupsRequest(SwitchId switchId, java.util.function.Consumer<MessageData> sender) {
try {
logger.debug("Loading installed groups for switch {}", switchId);
List<OFGroupDescStatsEntry> ofGroupDescStatsEntries = context.getSwitchManager().dumpGroups(DatapathId.of(switchId.toLong()));
List<GroupEntry> groups = ofGroupDescStatsEntries.stream().map(OfFlowStatsMapper.INSTANCE::toFlowGroupEntry).collect(Collectors.toList());
SwitchGroupEntries response = SwitchGroupEntries.builder().switchId(switchId).groupEntries(groups).build();
sender.accept(response);
} catch (SwitchOperationException e) {
logger.error("Dumping of groups on switch '{}' was unsuccessful: {}", switchId, e.getMessage());
ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription("The switch was not found when requesting a groups dump.").buildData();
sender.accept(errorData);
}
}
use of org.openkilda.messaging.info.rule.GroupEntry in project open-kilda by telstra.
the class GroupVerifyCommand method fromStatsEntry.
private MirrorConfig fromStatsEntry(OFGroupDescStatsEntry entry) {
GroupEntry groupEntry = OfFlowStatsMapper.INSTANCE.toFlowGroupEntry(entry);
GroupId groupId = new GroupId(groupEntry.getGroupId());
if (groupEntry.getBuckets().size() < 2) {
return null;
}
GroupBucket flowBucket = groupEntry.getBuckets().get(0);
int flowPort = Integer.parseInt(flowBucket.getApplyActions().getFlowOutput());
Set<MirrorConfigData> mirrorConfigDataSet = new HashSet<>();
for (int i = 1; i < groupEntry.getBuckets().size(); ++i) {
GroupBucket mirrorBucket = groupEntry.getBuckets().get(i);
int mirrorPort = Integer.parseInt(mirrorBucket.getApplyActions().getFlowOutput());
int mirrorVlan = mirrorBucket.getApplyActions().getSetFieldActions().stream().filter(action -> (MatchField.VLAN_VID.getName().equals(action.getFieldName()))).map(action -> Integer.valueOf(action.getFieldValue())).findFirst().orElse(0);
mirrorConfigDataSet.add(new MirrorConfigData(mirrorPort, mirrorVlan));
}
return MirrorConfig.builder().groupId(groupId).flowPort(flowPort).mirrorConfigDataSet(mirrorConfigDataSet).build();
}
Aggregations