use of org.openkilda.model.GroupId in project open-kilda by telstra.
the class FermaMirrorGroupRepository method exists.
@Override
public boolean exists(SwitchId switchId, GroupId groupId) {
String switchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(switchId);
Long groupIdAsLong = GroupIdConverter.INSTANCE.toGraphProperty(groupId);
try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(MirrorGroupFrame.GROUP_ID_PROPERTY, groupIdAsLong).has(MirrorGroupFrame.SWITCH_ID_PROPERTY, switchIdAsStr)).getRawTraversal()) {
return traversal.hasNext();
} catch (Exception e) {
throw new PersistenceException("Failed to traverse", e);
}
}
use of org.openkilda.model.GroupId in project open-kilda by telstra.
the class RecordHandler method doDeleteGroupRequest.
private void doDeleteGroupRequest(CommandMessage message) {
SwitchId switchId = ((DeleteGroupRequest) message.getData()).getSwitchId();
GroupId groupId = ((DeleteGroupRequest) message.getData()).getGroupId();
logger.debug("Delete group '{}' for switch '{}'", groupId, switchId);
handleSpeakerCommand(new GroupRemoveCommand(new MessageContext(message), switchId, groupId));
DeleteGroupResponse response = new DeleteGroupResponse(true);
String correlationId = message.getCorrelationId();
InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), correlationId);
getKafkaProducer().sendMessageAndTrack(context.getKafkaSwitchManagerTopic(), correlationId, infoMessage);
}
use of org.openkilda.model.GroupId in project open-kilda by telstra.
the class CommandBuilderImpl method buildGroupInstallContexts.
@Override
public List<GroupInstallContext> buildGroupInstallContexts(SwitchId switchId, List<Integer> groupIds) {
List<GroupInstallContext> groupInstallContexts = new ArrayList<>();
Map<PathId, MirrorGroup> mirrorGroups = new HashMap<>();
groupIds.stream().map(GroupId::new).map(mirrorGroupRepository::findByGroupId).flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty)).forEach(mirrorGroup -> mirrorGroups.put(mirrorGroup.getPathId(), mirrorGroup));
flowPathRepository.findBySegmentDestSwitch(switchId).forEach(flowPath -> {
if (mirrorGroups.containsKey(flowPath.getPathId())) {
PathSegment segment = flowPath.getSegments().stream().filter(pathSegment -> pathSegment.getDestSwitchId().equals(switchId)).findAny().orElseThrow(() -> new IllegalStateException(format("PathSegment not found, path %s, switch %s", flowPath, switchId)));
Flow flow = flowPath.getFlow();
if (segment.getDestSwitchId().equals(flowPath.getDestSwitchId())) {
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, flow.getDestSwitchId(), flow.getDestPort());
groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).build());
log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
}
}
});
flowPathRepository.findByEndpointSwitch(switchId).forEach(flowPath -> {
if (mirrorGroups.containsKey(flowPath.getPathId())) {
Flow flow = getFlow(flowPath);
if (flowPath.isOneSwitchFlow()) {
SwitchId swId = flowPath.isForward() ? flow.getDestSwitchId() : flow.getSrcSwitchId();
int port = flowPath.isForward() ? flow.getDestPort() : flow.getSrcPort();
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, swId, port);
groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).build());
log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
} else if (flowPath.getSrcSwitchId().equals(switchId)) {
if (flowPath.getSegments().isEmpty()) {
log.warn("Output port was not found for mirror config");
} else {
PathSegment foundIngressSegment = flowPath.getSegments().get(0);
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, foundIngressSegment.getSrcSwitchId(), foundIngressSegment.getSrcPort());
EncapsulationResources encapsulation = getEncapsulationResources(flowPath, flow);
groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).encapsulation(new FlowTransitEncapsulation(encapsulation.getTransitEncapsulationId(), encapsulation.getEncapsulationType())).egressSwitchId(flowPath.getDestSwitchId()).build());
log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
}
}
}
});
return groupInstallContexts;
}
use of org.openkilda.model.GroupId in project open-kilda by telstra.
the class OfInstructionsConverter method convertToRuleManagerAction.
/**
* Converts action.
*/
public Action convertToRuleManagerAction(OFAction action) {
switch(action.getType()) {
case PUSH_VLAN:
return new PushVlanAction();
case POP_VLAN:
return new PopVlanAction();
case METER:
OFActionMeter meterAction = (OFActionMeter) action;
MeterId meterId = new MeterId(meterAction.getMeterId());
return new MeterAction(meterId);
case GROUP:
OFActionGroup groupAction = (OFActionGroup) action;
GroupId groupId = new GroupId(groupAction.getGroup().getGroupNumber());
return new GroupAction(groupId);
case OUTPUT:
OFActionOutput outputAction = (OFActionOutput) action;
PortNumber portNumber = convertPort(outputAction.getPort());
return new PortOutAction(portNumber);
case EXPERIMENTER:
if (action instanceof OFActionNoviflowPushVxlanTunnel) {
OFActionNoviflowPushVxlanTunnel pushNoviVxlan = (OFActionNoviflowPushVxlanTunnel) action;
return PushVxlanAction.builder().type(ActionType.PUSH_VXLAN_NOVIFLOW).vni((int) pushNoviVxlan.getVni()).srcMacAddress(convertMac(pushNoviVxlan.getEthSrc())).dstMacAddress(convertMac(pushNoviVxlan.getEthDst())).srcIpv4Address(convertIPv4Address(pushNoviVxlan.getIpv4Src())).dstIpv4Address(convertIPv4Address(pushNoviVxlan.getIpv4Dst())).udpSrc(pushNoviVxlan.getUdpSrc()).build();
} else if (action instanceof OFActionKildaPushVxlanField) {
OFActionKildaPushVxlanField pushKildaVxlan = (OFActionKildaPushVxlanField) action;
return PushVxlanAction.builder().type(ActionType.PUSH_VXLAN_OVS).vni((int) pushKildaVxlan.getVni()).srcMacAddress(convertMac(pushKildaVxlan.getEthSrc())).dstMacAddress(convertMac(pushKildaVxlan.getEthDst())).srcIpv4Address(convertIPv4Address(pushKildaVxlan.getIpv4Src())).dstIpv4Address(convertIPv4Address(pushKildaVxlan.getIpv4Dst())).udpSrc(pushKildaVxlan.getUdpSrc()).build();
} else if (action instanceof OFActionNoviflowCopyField) {
OFActionNoviflowCopyField copyField = (OFActionNoviflowCopyField) action;
return CopyFieldAction.builder().numberOfBits(copyField.getNBits()).srcOffset(copyField.getSrcOffset()).dstOffset(copyField.getDstOffset()).oxmSrcHeader(convertOxmHeader(copyField.getOxmSrcHeader())).oxmDstHeader(convertOxmHeader(copyField.getOxmDstHeader())).build();
} else if (action instanceof OFActionNoviflowSwapField) {
OFActionNoviflowSwapField swapField = (OFActionNoviflowSwapField) action;
return SwapFieldAction.builder().type(ActionType.NOVI_SWAP_FIELD).numberOfBits(swapField.getNBits()).srcOffset(swapField.getSrcOffset()).dstOffset(swapField.getDstOffset()).oxmSrcHeader(convertOxmHeader(swapField.getOxmSrcHeader())).oxmDstHeader(convertOxmHeader(swapField.getOxmDstHeader())).build();
} else if (action instanceof OFActionKildaSwapField) {
OFActionKildaSwapField swapField = (OFActionKildaSwapField) action;
return SwapFieldAction.builder().type(ActionType.KILDA_SWAP_FIELD).numberOfBits(swapField.getNBits()).srcOffset(swapField.getSrcOffset()).dstOffset(swapField.getDstOffset()).oxmSrcHeader(convertOxmHeader(swapField.getOxmSrcHeader())).oxmDstHeader(convertOxmHeader(swapField.getOxmDstHeader())).build();
} else if (action instanceof OFActionNoviflowPopVxlanTunnel) {
return new PopVxlanAction(ActionType.POP_VXLAN_NOVIFLOW);
} else if (action instanceof OFActionKildaPopVxlanField) {
return new PopVxlanAction(ActionType.POP_VXLAN_OVS);
} else {
throw new IllegalStateException(format("Unknown experimenter action %s", action.getType()));
}
case SET_FIELD:
OFActionSetField setFieldAction = (OFActionSetField) action;
return convertOxm(setFieldAction.getField());
case SET_VLAN_VID:
OFActionSetVlanVid setVlanVid = (OFActionSetVlanVid) action;
return SetFieldAction.builder().field(Field.VLAN_VID).value(setVlanVid.getVlanVid().getVlan()).build();
default:
throw new IllegalStateException(format("Unknown action type %s", action.getType()));
}
}
use of org.openkilda.model.GroupId in project open-kilda by telstra.
the class OfGroupConverter method convertToGroupSpeakerData.
/**
* Convert stats entry.
*/
public GroupSpeakerData convertToGroupSpeakerData(OFGroupDescStatsEntry entry) {
GroupId groupId = new GroupId(entry.getGroup().getGroupNumber());
GroupType type = fromOfGroupType(entry.getGroupType());
List<Bucket> buckets = new ArrayList<>();
List<OFBucket> ofBuckets = entry.getBuckets();
for (OFBucket bucket : ofBuckets) {
buckets.add(fromOfBucket(bucket));
}
return GroupSpeakerData.builder().groupId(groupId).type(type).buckets(buckets).build();
}
Aggregations