use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.
the class DefaultVirtualPacketProvider method devirtualize.
/**
* Translate the requested virtual outbound packet into
* a set of physical OutboundPacket.
* See {@link org.onosproject.net.packet.OutboundPacket}
*
* @param packet an OutboundPacket to be translated
* @return a set of de-virtualized (physical) OutboundPacket
*/
private Set<OutboundPacket> devirtualize(NetworkId networkId, OutboundPacket packet) {
Set<OutboundPacket> outboundPackets = new HashSet<>();
Set<VirtualPort> vPorts = vnaService.getVirtualPorts(networkId, packet.sendThrough());
TrafficTreatment.Builder commonTreatmentBuilder = DefaultTrafficTreatment.builder();
packet.treatment().allInstructions().stream().filter(i -> i.type() != Instruction.Type.OUTPUT).forEach(i -> commonTreatmentBuilder.add(i));
TrafficTreatment commonTreatment = commonTreatmentBuilder.build();
PortNumber vOutPortNum = packet.treatment().allInstructions().stream().filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).findFirst().get();
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, packet.sendThrough());
return outboundPackets;
}
ConnectPoint egressPoint = optionalCpOut.get();
TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(egressPoint.port()).build();
OutboundPacket outboundPacket = new DefaultOutboundPacket(egressPoint.deviceId(), treatment, packet.data());
outboundPackets.add(outboundPacket);
} else {
if (vOutPortNum == PortNumber.FLOOD) {
for (VirtualPort outPort : vPorts) {
ConnectPoint cpOut = outPort.realizedBy();
if (cpOut != null) {
TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(cpOut.port()).build();
OutboundPacket outboundPacket = new DefaultOutboundPacket(cpOut.deviceId(), treatment, packet.data());
outboundPackets.add(outboundPacket);
} else {
log.warn("Port {} is not realized yet, in Network {}, Device {}", outPort.number(), networkId, packet.sendThrough());
}
}
}
}
return outboundPackets;
}
use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.
the class DefaultVirtualPacketProvider method getMappedVirtualPort.
/**
* Find the corresponding virtual port with the physical port.
*
* @param cp the connect point for the physical network
* @return a virtual port
*/
private VirtualPort getMappedVirtualPort(ConnectPoint cp) {
Set<TenantId> tIds = vnaService.getTenantIds();
Set<VirtualNetwork> vNetworks = new HashSet<>();
tIds.forEach(tid -> vNetworks.addAll(vnaService.getVirtualNetworks(tid)));
for (VirtualNetwork vNet : vNetworks) {
Set<VirtualDevice> vDevices = vnaService.getVirtualDevices(vNet.id());
Set<VirtualPort> vPorts = new HashSet<>();
vDevices.forEach(dev -> vPorts.addAll(vnaService.getVirtualPorts(dev.networkId(), dev.id())));
VirtualPort vPort = vPorts.stream().filter(vp -> vp.realizedBy().equals(cp)).findFirst().orElse(null);
if (vPort != null) {
return vPort;
}
}
return null;
}
use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.
the class VirtualNetworkWebResource method createVirtualPort.
/**
* Creates a virtual network port in a virtual device in a virtual network.
*
* @param networkId network identifier
* @param virtDeviceId virtual device identifier
* @param stream virtual port JSON stream
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel VirtualPort
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{networkId}/devices/{deviceId}/ports")
public Response createVirtualPort(@PathParam("networkId") long networkId, @PathParam("deviceId") String virtDeviceId, InputStream stream) {
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
// final VirtualPort vportReq = codec(VirtualPort.class).decode(jsonTree, this);
JsonNode specifiedNetworkId = jsonTree.get("networkId");
JsonNode specifiedDeviceId = jsonTree.get("deviceId");
if (specifiedNetworkId == null || specifiedNetworkId.asLong() != (networkId)) {
throw new IllegalArgumentException(INVALID_FIELD + "networkId");
}
if (specifiedDeviceId == null || !specifiedDeviceId.asText().equals(virtDeviceId)) {
throw new IllegalArgumentException(INVALID_FIELD + "deviceId");
}
JsonNode specifiedPortNum = jsonTree.get("portNum");
JsonNode specifiedPhysDeviceId = jsonTree.get("physDeviceId");
JsonNode specifiedPhysPortNum = jsonTree.get("physPortNum");
final NetworkId nid = NetworkId.networkId(networkId);
DeviceId vdevId = DeviceId.deviceId(virtDeviceId);
ConnectPoint realizedBy = new ConnectPoint(DeviceId.deviceId(specifiedPhysDeviceId.asText()), PortNumber.portNumber(specifiedPhysPortNum.asText()));
VirtualPort vport = vnetAdminService.createVirtualPort(nid, vdevId, PortNumber.portNumber(specifiedPortNum.asText()), realizedBy);
UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("vnets").path(specifiedNetworkId.asText()).path("devices").path(specifiedDeviceId.asText()).path("ports").path(vport.number().toString());
return Response.created(locationBuilder.build()).build();
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.
the class VirtualPortBindCommand method doExecute.
@Override
protected void doExecute() {
VirtualNetworkAdminService service = get(VirtualNetworkAdminService.class);
DeviceService deviceService = get(DeviceService.class);
VirtualPort vPort = getVirtualPort(PortNumber.portNumber(portNum));
checkNotNull(vPort, "The virtual Port does not exist");
ConnectPoint realizedBy = new ConnectPoint(DeviceId.deviceId(physDeviceId), PortNumber.portNumber(physPortNum));
service.bindVirtualPort(NetworkId.networkId(networkId), DeviceId.deviceId(deviceId), PortNumber.portNumber(portNum), realizedBy);
print("Virtual port is successfully bound.");
}
use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.
the class VirtualPortBindCommand 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();
}
Aggregations