use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.
the class DefaultVirtualFlowRuleProvider method extractEgressPoints.
/**
* Extract egress connect point of the physical network
* from the requested traffic treatment.
*
* @param networkId the virtual network identifier
* @param deviceId the virtual device identifier
* @param treatment the traffic treatment to extract ingress point
* @return the egress connect point of the physical network
*/
private ConnectPoint extractEgressPoints(NetworkId networkId, DeviceId deviceId, TrafficTreatment treatment) {
Set<VirtualPort> vPorts = vnService.getVirtualPorts(networkId, deviceId);
PortNumber vOutPortNum = treatment.allInstructions().stream().filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).findFirst().get();
Optional<ConnectPoint> optionalCpOut = vPorts.stream().filter(v -> v.number().equals(vOutPortNum)).map(VirtualPort::realizedBy).findFirst();
if (!optionalCpOut.isPresent()) {
if (vOutPortNum.isLogical()) {
return new ConnectPoint(DeviceId.deviceId("vNet"), vOutPortNum);
}
log.warn("Port {} is not realized yet, in Network {}, Device {}", vOutPortNum, networkId, deviceId);
return null;
}
return optionalCpOut.get();
}
use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.
the class DefaultVirtualMeterProvider method activate.
@Activate
public void activate() {
providerRegistryService.registerProvider(this);
internalMeterListener = new InternalMeterListener();
idGenerator = getIdGenerator();
pendingOperations = CacheBuilder.newBuilder().expireAfterWrite(TIMEOUT, TimeUnit.SECONDS).removalListener((RemovalNotification<Long, VirtualMeterOperation> notification) -> {
if (notification.getCause() == RemovalCause.EXPIRED) {
NetworkId networkId = notification.getValue().networkId();
MeterOperation op = notification.getValue().operation();
VirtualMeterProviderService providerService = (VirtualMeterProviderService) providerRegistryService.getProviderService(networkId, VirtualMeterProvider.class);
providerService.meterOperationFailed(op, MeterFailReason.TIMEOUT);
}
}).build();
meterService.addListener(internalMeterListener);
log.info("Started");
}
use of org.onosproject.incubator.net.virtual.NetworkId 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.NetworkId in project onos by opennetworkinglab.
the class VirtualHostCodec method decode.
@Override
public VirtualHost decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
NetworkId nId = NetworkId.networkId(Long.parseLong(extractMember(NETWORK_ID, json)));
MacAddress mac = MacAddress.valueOf(json.get("mac").asText());
VlanId vlanId = VlanId.vlanId((short) json.get("vlan").asInt(VlanId.UNTAGGED));
Set<HostLocation> locations = new HashSet<>();
JsonNode locationNodes = json.get("locations");
locationNodes.forEach(locationNode -> {
PortNumber portNumber = PortNumber.portNumber(locationNode.get("port").asText());
DeviceId deviceId = DeviceId.deviceId(locationNode.get("elementId").asText());
locations.add(new HostLocation(deviceId, portNumber, 0));
});
HostId id = HostId.hostId(mac, vlanId);
Iterator<JsonNode> ipStrings = json.get("ipAddresses").elements();
Set<IpAddress> ips = new HashSet<>();
while (ipStrings.hasNext()) {
ips.add(IpAddress.valueOf(ipStrings.next().asText()));
}
return new DefaultVirtualHost(nId, id, mac, vlanId, locations, ips);
}
use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.
the class VirtualNetworkCodec method decode.
@Override
public VirtualNetwork decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
NetworkId nId = NetworkId.networkId(Long.parseLong(extractMember(NETWORK_ID, json)));
TenantId tId = TenantId.tenantId(extractMember(TENANT_ID, json));
return new DefaultVirtualNetwork(nId, tId);
}
Aggregations