use of org.openkilda.model.GroupId in project open-kilda by telstra.
the class FermaMirrorGroupRepositoryTest method findUnassignedMirrorGroupAndCreate.
private long findUnassignedMirrorGroupAndCreate(String flowId, String pathId) {
GroupId availableGroupId = mirrorGroupRepository.findFirstUnassignedGroupId(theSwitch.getSwitchId(), MIN_GROUP_ID, MAX_GROUP_ID).get();
MirrorGroup mirrorGroup = MirrorGroup.builder().switchId(theSwitch.getSwitchId()).groupId(availableGroupId).pathId(new PathId(flowId + "_" + pathId)).flowId(flowId).mirrorGroupType(MirrorGroupType.TRAFFIC_INTEGRITY).mirrorDirection(MirrorDirection.INGRESS).build();
mirrorGroupRepository.add(mirrorGroup);
return availableGroupId.getValue();
}
use of org.openkilda.model.GroupId 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.openkilda.model.GroupId in project open-kilda by telstra.
the class SimpleSwitchRuleConverterTest method buildFlow.
private Flow buildFlow(FlowEncapsulationType flowEncapsulationType, boolean checkWithGroup) {
Switch switchA = Switch.builder().switchId(TEST_SWITCH_ID_A).description("").build();
Switch switchB = Switch.builder().switchId(TEST_SWITCH_ID_B).description("").build();
Switch switchC = Switch.builder().switchId(TEST_SWITCH_ID_C).description("").build();
Flow flow = Flow.builder().flowId(TEST_FLOW_ID_A).srcSwitch(switchA).srcPort(FLOW_A_SRC_PORT).srcVlan(FLOW_A_SRC_VLAN).destSwitch(switchC).destPort(FLOW_A_DST_PORT).destVlan(FLOW_A_DST_VLAN).allocateProtectedPath(true).encapsulationType(flowEncapsulationType).bandwidth(FLOW_A_BANDWIDTH).status(FlowStatus.UP).build();
FlowPath forwardFlowPath = FlowPath.builder().pathId(FLOW_A_FORWARD_PATH_ID).cookie(new FlowSegmentCookie(FLOW_A_FORWARD_COOKIE_VALUE)).meterId(new MeterId(FLOW_A_FORWARD_METER_ID)).srcSwitch(switchA).destSwitch(switchC).status(FlowPathStatus.ACTIVE).bandwidth(FLOW_A_BANDWIDTH).build();
flow.setForwardPath(forwardFlowPath);
PathSegment forwardSegmentA = PathSegment.builder().pathId(forwardFlowPath.getPathId()).srcSwitch(switchA).srcPort(FLOW_A_SEGMENT_A_SRC_PORT).destSwitch(switchB).destPort(FLOW_A_SEGMENT_A_DST_PORT).build();
PathSegment forwardSegmentB = PathSegment.builder().pathId(forwardFlowPath.getPathId()).srcSwitch(switchB).srcPort(FLOW_A_SEGMENT_B_SRC_PORT).destSwitch(switchC).destPort(FLOW_A_SEGMENT_B_DST_PORT).build();
forwardFlowPath.setSegments(Lists.newArrayList(forwardSegmentA, forwardSegmentB));
if (checkWithGroup) {
FlowMirrorPoints flowMirrorPoints = FlowMirrorPoints.builder().mirrorSwitch(switchA).mirrorGroup(MirrorGroup.builder().switchId(TEST_SWITCH_ID_A).groupId(new GroupId(FLOW_GROUP_ID_A)).pathId(FLOW_A_FORWARD_PATH_ID).flowId(TEST_FLOW_ID_A).mirrorGroupType(MirrorGroupType.TRAFFIC_INTEGRITY).mirrorDirection(MirrorDirection.INGRESS).build()).build();
FlowMirrorPath flowMirrorPath = FlowMirrorPath.builder().pathId(new PathId("mirror_path")).mirrorSwitch(switchA).egressSwitch(switchA).egressPort(FLOW_GROUP_ID_A_OUT_PORT).egressOuterVlan(FLOW_GROUP_ID_A_OUT_VLAN).build();
flowMirrorPoints.addPaths(flowMirrorPath);
forwardFlowPath.addFlowMirrorPoints(flowMirrorPoints);
}
return flow;
}
use of org.openkilda.model.GroupId in project open-kilda by telstra.
the class FermaMirrorGroupRepository method findFirstUnassignedGroupId.
@Override
public Optional<GroupId> findFirstUnassignedGroupId(SwitchId switchId, GroupId lowestGroupId, GroupId highestGroupId) {
String switchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(switchId);
Long lowestGroupIdAsLong = GroupIdConverter.INSTANCE.toGraphProperty(lowestGroupId);
Long highestGroupIdAsLong = GroupIdConverter.INSTANCE.toGraphProperty(highestGroupId);
try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(MirrorGroupFrame.FRAME_LABEL).has(MirrorGroupFrame.SWITCH_ID_PROPERTY, switchIdAsStr).has(MirrorGroupFrame.GROUP_ID_PROPERTY, P.gte(lowestGroupIdAsLong)).has(MirrorGroupFrame.GROUP_ID_PROPERTY, P.lt(highestGroupIdAsLong)).values(MirrorGroupFrame.GROUP_ID_PROPERTY).order().math("_ + 1").as("a").where(__.not(__.V().hasLabel(MirrorGroupFrame.FRAME_LABEL).has(MirrorGroupFrame.SWITCH_ID_PROPERTY, switchIdAsStr).values(MirrorGroupFrame.GROUP_ID_PROPERTY).where(P.eq("a")))).select("a").limit(1)).getRawTraversal()) {
if (traversal.hasNext()) {
return traversal.tryNext().map(l -> ((Double) l).longValue()).map(GroupIdConverter.INSTANCE::toEntityAttribute);
}
} catch (Exception e) {
throw new PersistenceException("Failed to traverse", e);
}
try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(MirrorGroupFrame.FRAME_LABEL).has(MirrorGroupFrame.SWITCH_ID_PROPERTY, switchIdAsStr).has(MirrorGroupFrame.GROUP_ID_PROPERTY, lowestGroupIdAsLong)).getRawTraversal()) {
if (!traversal.hasNext()) {
return Optional.of(lowestGroupId);
}
} catch (Exception e) {
throw new PersistenceException("Failed to traverse", e);
}
return Optional.empty();
}
use of org.openkilda.model.GroupId in project open-kilda by telstra.
the class CommandBuilderImpl method makeMirrorConfig.
private MirrorConfig makeMirrorConfig(@NonNull FlowPath flowPath, @NonNull SwitchId mirrorSwitchId, int mirrorPort) {
MirrorConfig mirrorConfig = null;
FlowMirrorPoints flowMirrorPoints = flowPath.getFlowMirrorPointsSet().stream().filter(mirrorPoints -> mirrorSwitchId.equals(mirrorPoints.getMirrorSwitchId())).findFirst().orElse(null);
if (flowMirrorPoints != null) {
Set<MirrorConfigData> mirrorConfigDataSet = flowMirrorPoints.getMirrorPaths().stream().map(mirrorPath -> new MirrorConfigData(mirrorPath.getEgressPort(), mirrorPath.getEgressOuterVlan())).collect(Collectors.toSet());
if (!mirrorConfigDataSet.isEmpty()) {
mirrorConfig = MirrorConfig.builder().groupId(flowMirrorPoints.getMirrorGroupId()).flowPort(mirrorPort).mirrorConfigDataSet(mirrorConfigDataSet).build();
}
}
return mirrorConfig;
}
Aggregations