use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.
the class VirtualPortStateCommand method getVirtualPort.
/**
* Returns the virtual port matching the device and port identifier.
*
* @param aPortNumber port identifier
* @return matching virtual port, or null.
*/
private VirtualPort getVirtualPort(PortNumber aPortNumber) {
VirtualNetworkService service = get(VirtualNetworkService.class);
Set<VirtualPort> ports = service.getVirtualPorts(NetworkId.networkId(networkId), DeviceId.deviceId(deviceId));
return ports.stream().filter(p -> p.number().equals(aPortNumber)).findFirst().get();
}
use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.
the class DistributedVirtualNetworkStore method addPort.
@Override
public VirtualPort addPort(NetworkId networkId, DeviceId deviceId, PortNumber portNumber, ConnectPoint realizedBy) {
checkState(networkExists(networkId), "The network has not been added.");
Set<VirtualPort> virtualPortSet = networkIdVirtualPortSetMap.get(networkId);
if (virtualPortSet == null) {
virtualPortSet = new HashSet<>();
}
VirtualDevice device = deviceIdVirtualDeviceMap.get(new VirtualDeviceId(networkId, deviceId));
checkNotNull(device, "The device has not been created for deviceId: " + deviceId);
checkState(!virtualPortExists(networkId, deviceId, portNumber), "The requested Port Number has been added.");
VirtualPort virtualPort = new DefaultVirtualPort(networkId, device, portNumber, realizedBy);
virtualPortSet.add(virtualPort);
networkIdVirtualPortSetMap.put(networkId, virtualPortSet);
notifyDelegate(new VirtualNetworkEvent(VirtualNetworkEvent.Type.VIRTUAL_PORT_ADDED, networkId, device, virtualPort));
return virtualPort;
}
use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.
the class DistributedVirtualNetworkStore method updatePortState.
@Override
public void updatePortState(NetworkId networkId, DeviceId deviceId, PortNumber portNumber, boolean isEnabled) {
checkState(networkExists(networkId), "No network with NetworkId %s exists.", networkId);
VirtualDevice device = deviceIdVirtualDeviceMap.get(new VirtualDeviceId(networkId, deviceId));
checkNotNull(device, "No device %s exists in NetworkId: %s", deviceId, networkId);
Set<VirtualPort> virtualPortSet = networkIdVirtualPortSetMap.get(networkId);
checkNotNull(virtualPortSet, "No port has been created for NetworkId: %s", networkId);
Optional<VirtualPort> virtualPortOptional = virtualPortSet.stream().filter(p -> p.element().id().equals(deviceId) && p.number().equals(portNumber)).findFirst();
checkState(virtualPortOptional.isPresent(), "The virtual port has not been added.");
VirtualPort oldPort = virtualPortOptional.get();
if (oldPort.isEnabled() == isEnabled) {
log.debug("No change in port state - port not updated");
return;
}
VirtualPort newPort = new DefaultVirtualPort(networkId, device, portNumber, isEnabled, oldPort.realizedBy());
virtualPortSet.remove(oldPort);
virtualPortSet.add(newPort);
networkIdVirtualPortSetMap.put(networkId, virtualPortSet);
notifyDelegate(new VirtualNetworkEvent(VirtualNetworkEvent.Type.VIRTUAL_PORT_UPDATED, networkId, device, newPort));
log.debug("port state changed from {} to {}", oldPort.isEnabled(), isEnabled);
}
use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.
the class DefaultVirtualFlowRuleProvider method devirtualize.
/**
* Translate the requested virtual flow rules into physical flow rules.
* The translation could be one to many.
*
* @param flowRule A flow rule from underlying data plane to be translated
* @return A set of flow rules for physical network
*/
private Set<FlowRule> devirtualize(NetworkId networkId, FlowRule flowRule) {
Set<FlowRule> outRules = new HashSet<>();
Set<ConnectPoint> ingressPoints = extractIngressPoints(networkId, flowRule.deviceId(), flowRule.selector());
ConnectPoint egressPoint = extractEgressPoints(networkId, flowRule.deviceId(), flowRule.treatment());
if (egressPoint == null) {
return outRules;
}
TrafficSelector.Builder commonSelectorBuilder = DefaultTrafficSelector.builder();
flowRule.selector().criteria().stream().filter(c -> c.type() != Criterion.Type.IN_PORT).forEach(c -> commonSelectorBuilder.add(c));
TrafficSelector commonSelector = commonSelectorBuilder.build();
TrafficTreatment.Builder commonTreatmentBuilder = DefaultTrafficTreatment.builder();
flowRule.treatment().allInstructions().stream().filter(i -> i.type() != Instruction.Type.OUTPUT).forEach(i -> commonTreatmentBuilder.add(i));
TrafficTreatment commonTreatment = commonTreatmentBuilder.build();
for (ConnectPoint ingressPoint : ingressPoints) {
if (egressPoint.port() == PortNumber.FLOOD) {
Set<ConnectPoint> outPoints = vnService.getVirtualPorts(networkId, flowRule.deviceId()).stream().map(VirtualPort::realizedBy).filter(p -> !p.equals(ingressPoint)).collect(Collectors.toSet());
for (ConnectPoint outPoint : outPoints) {
outRules.addAll(generateRules(networkId, ingressPoint, outPoint, commonSelector, commonTreatment, flowRule));
}
} else {
outRules.addAll(generateRules(networkId, ingressPoint, egressPoint, commonSelector, commonTreatment, flowRule));
}
}
return outRules;
}
use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.
the class DefaultVirtualPacketProvider method devirtualizeContext.
/**
* Translate the requested virtual packet context into
* a set of physical outbound packets.
*
* @param context A handled virtual packet context
*/
private Set<OutboundPacket> devirtualizeContext(VirtualPacketContext context) {
Set<OutboundPacket> outboundPackets = new HashSet<>();
NetworkId networkId = context.networkId();
TrafficTreatment vTreatment = context.treatmentBuilder().build();
DeviceId sendThrough = context.outPacket().sendThrough();
Set<VirtualPort> vPorts = vnaService.getVirtualPorts(networkId, sendThrough);
PortNumber vOutPortNum = vTreatment.allInstructions().stream().filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).findFirst().get();
TrafficTreatment.Builder commonTreatmentBuilder = DefaultTrafficTreatment.builder();
vTreatment.allInstructions().stream().filter(i -> i.type() != Instruction.Type.OUTPUT).forEach(i -> commonTreatmentBuilder.add(i));
TrafficTreatment commonTreatment = commonTreatmentBuilder.build();
if (!vOutPortNum.isLogical()) {
Optional<ConnectPoint> optionalCpOut = vPorts.stream().filter(v -> v.number().equals(vOutPortNum)).map(v -> v.realizedBy()).findFirst();
if (!optionalCpOut.isPresent()) {
log.warn("Port {} is not realized yet, in Network {}, Device {}", vOutPortNum, networkId, sendThrough);
return outboundPackets;
}
ConnectPoint egressPoint = optionalCpOut.get();
TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(egressPoint.port()).build();
OutboundPacket outboundPacket = new DefaultOutboundPacket(egressPoint.deviceId(), treatment, context.outPacket().data());
outboundPackets.add(outboundPacket);
} else {
if (vOutPortNum == PortNumber.FLOOD) {
Set<VirtualPort> outPorts = vPorts.stream().filter(vp -> !vp.number().isLogical()).filter(vp -> vp.number() != context.inPacket().receivedFrom().port()).collect(Collectors.toSet());
for (VirtualPort outPort : outPorts) {
ConnectPoint cpOut = outPort.realizedBy();
if (cpOut != null) {
TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(cpOut.port()).build();
OutboundPacket outboundPacket = new DefaultOutboundPacket(cpOut.deviceId(), treatment, context.outPacket().data());
outboundPackets.add(outboundPacket);
} else {
log.warn("Port {} is not realized yet, in Network {}, Device {}", outPort.number(), networkId, sendThrough);
}
}
}
}
return outboundPackets;
}
Aggregations