use of org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry 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.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry in project open-kilda by telstra.
the class GroupVerifyCommand method handleGroupStats.
private MirrorConfig handleGroupStats(List<OFGroupDescStatsReply> groupDescStatsReply) {
OFGroupDescStatsEntry target = null;
List<OFGroupDescStatsEntry> groupDescStatsEntries = groupDescStatsReply.stream().map(OFGroupDescStatsReply::getEntries).flatMap(List::stream).collect(toList());
for (OFGroupDescStatsEntry entry : groupDescStatsEntries) {
if (mirrorConfig.getGroupId().intValue() == entry.getGroup().getGroupNumber()) {
target = entry;
break;
}
}
if (target == null) {
throw maskCallbackException(new SwitchMissingGroupException(getSw().getId(), mirrorConfig.getGroupId()));
}
validateGroupConfig(target);
return mirrorConfig;
}
use of org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry 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.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry 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();
}
use of org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry in project open-kilda by telstra.
the class SwitchManagerTest method mockGetGroupsRequest.
private void mockGetGroupsRequest(List<Integer> groupIds) throws Exception {
List<OFGroupDescStatsEntry> meterConfigs = new ArrayList<>(groupIds.size());
for (Integer groupId : groupIds) {
OFBucket firstBucket = mock(OFBucket.class);
OFBucket secondBucket = mock(OFBucket.class);
OFActionSetField setDestMacAction = ofFactory.actions().buildSetField().setField(ofFactory.oxms().buildEthDst().setValue(convertDpIdToMac(dpid)).build()).build();
OFActionOutput sendToControllerAction = ofFactory.actions().output(OFPort.CONTROLLER, 0xFFFFFFFF);
TransportPort udpPort = TransportPort.of(LATENCY_PACKET_UDP_PORT);
OFActionSetField setUdpDstAction = ofFactory.actions().setField(ofFactory.oxms().udpDst(udpPort));
OFActionOutput sendInPortAction = ofFactory.actions().output(OFPort.IN_PORT, 0xFFFFFFFF);
expect(firstBucket.getActions()).andStubReturn(Lists.newArrayList(setDestMacAction, sendToControllerAction));
expect(secondBucket.getActions()).andStubReturn(Lists.newArrayList(setUdpDstAction, sendInPortAction));
OFGroupDescStatsEntry groupEntry = mock(OFGroupDescStatsEntry.class);
expect(groupEntry.getGroup()).andStubReturn(OFGroup.of(groupId));
expect(groupEntry.getBuckets()).andStubReturn(Lists.newArrayList(firstBucket, secondBucket));
replay(firstBucket, secondBucket, groupEntry);
meterConfigs.add(groupEntry);
}
OFGroupDescStatsReply statsReply = mock(OFGroupDescStatsReply.class);
expect(statsReply.getEntries()).andStubReturn(meterConfigs);
ListenableFuture<List<OFGroupDescStatsReply>> ofStatsFuture = mock(ListenableFuture.class);
expect(ofStatsFuture.get(anyLong(), anyObject())).andStubReturn(Collections.singletonList(statsReply));
expect(iofSwitch.writeStatsRequest(isA(OFGroupDescStatsRequest.class))).andStubReturn(ofStatsFuture);
replay(statsReply, ofStatsFuture);
}
Aggregations