use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class SimpleIntManager method configDevice.
protected boolean configDevice(DeviceId deviceId) {
// Returns true if config was successful, false if not and a clean up is
// needed.
final Device device = deviceService.getDevice(deviceId);
if (device == null || !device.is(IntProgrammable.class)) {
return true;
}
if (isNotIntConfigured()) {
log.warn("Missing INT config, aborting programming of INT device {}", deviceId);
return true;
}
final boolean isEdge = !hostService.getConnectedHosts(deviceId).isEmpty();
final IntDeviceRole intDeviceRole = isEdge ? IntDeviceRole.SOURCE_SINK : IntDeviceRole.TRANSIT;
log.info("Started programming of INT device {} with role {}...", deviceId, intDeviceRole);
final IntProgrammable intProg = device.as(IntProgrammable.class);
if (!isIntStarted()) {
// Leave device with no INT configuration.
return true;
}
if (!intProg.init()) {
log.warn("Unable to init INT pipeline on {}", deviceId);
return false;
}
boolean supportSource = intProg.supportsFunctionality(IntProgrammable.IntFunctionality.SOURCE);
boolean supportSink = intProg.supportsFunctionality(IntProgrammable.IntFunctionality.SINK);
boolean supportPostcard = intProg.supportsFunctionality(IntProgrammable.IntFunctionality.POSTCARD);
if (intDeviceRole != IntDeviceRole.SOURCE_SINK && !supportPostcard) {
// Stop here, no more configuration needed for transit devices unless it support postcard.
return true;
}
if (supportSink || supportPostcard) {
if (!intProg.setupIntConfig(intConfig.get())) {
log.warn("Unable to apply INT report config on {}", deviceId);
return false;
}
}
// Port configuration.
final Set<PortNumber> hostPorts = deviceService.getPorts(deviceId).stream().map(port -> new ConnectPoint(deviceId, port.number())).filter(cp -> !hostService.getConnectedHosts(cp).isEmpty()).map(ConnectPoint::port).collect(Collectors.toSet());
for (PortNumber port : hostPorts) {
if (supportSource) {
log.info("Setting port {}/{} as INT source port...", deviceId, port);
if (!intProg.setSourcePort(port)) {
log.warn("Unable to set INT source port {} on {}", port, deviceId);
return false;
}
}
if (supportSink) {
log.info("Setting port {}/{} as INT sink port...", deviceId, port);
if (!intProg.setSinkPort(port)) {
log.warn("Unable to set INT sink port {} on {}", port, deviceId);
return false;
}
}
}
if (!supportSource && !supportPostcard) {
// it supports postcard mode.
return true;
}
// Apply intents.
// This is a trivial implementation where we simply get the
// corresponding INT objective from an intent and we apply to all
// device which support reporting.
int appliedCount = 0;
for (Versioned<IntIntent> versionedIntent : intentMap.values()) {
IntIntent intent = versionedIntent.value();
IntObjective intObjective = getIntObjective(intent);
if (intent.telemetryMode() == IntIntent.TelemetryMode.INBAND_TELEMETRY && supportSource) {
intProg.addIntObjective(intObjective);
appliedCount++;
} else if (intent.telemetryMode() == IntIntent.TelemetryMode.POSTCARD && supportPostcard) {
intProg.addIntObjective(intObjective);
appliedCount++;
} else {
log.warn("Device {} does not support intent {}.", deviceId, intent);
}
}
log.info("Completed programming of {}, applied {} INT objectives of {} total", deviceId, appliedCount, intentMap.size());
return true;
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class DefaultCheckLoop method processOneOutputInstruction.
/**
* Process one output instruction.
*
* Params are passed from processOneInstruction directly,
* and obey the same rules.
*
* @param instOne the instruction to be processed
* @param currentDeviceId id of the device we are now in
* @param initPkt the packet before being copied
* @param matchedPkt the packet which matched the flow entry,
* to which this instruction belongs
* @param isFindLoop indicate if it is invoked by findLoop method
* @param firstEntry the flow entry from which the packet is generated
* @return true, if a loop is discovered;
* false, 1. invoked by matchDeviceFlows method, and detected no loop;
* 2. invoked by findLoop method
*/
private boolean processOneOutputInstruction(Instruction instOne, DeviceId currentDeviceId, TsLoopPacket initPkt, TsLoopPacket matchedPkt, boolean isFindLoop, FlowEntry firstEntry) {
OutputInstruction instOutput = (OutputInstruction) instOne;
PortNumber instPort = instOutput.port();
if (!instPort.isLogical()) {
// single OUTPUT - NIC or normal port
Set<Link> dstLink = tsGetEgressLinks(new ConnectPoint(currentDeviceId, instPort));
if (!dstLink.isEmpty()) {
// TODO - now, just deal with the first destination.
// will there be more destinations?
Link dstThisLink = dstLink.iterator().next();
ConnectPoint dstPoint = dstThisLink.dst();
// check output to devices only (output to a host is normal)
if (isDevice(dstPoint)) {
PortCriterion oldInPort = updatePktInportPerHop(matchedPkt, dstPoint);
matchedPkt.pushPathLink(dstThisLink);
TsLoopPacket newNewPkt = matchedPkt.copyPacketMatch();
boolean loopFound = matchDeviceFlows(dstPoint.deviceId(), newNewPkt);
if (isFindLoop) {
if (loopFound) {
loops.add(newNewPkt);
updateExcludeDeviceSet(newNewPkt);
}
matchedPkt.resetLinkFlow(firstEntry);
} else {
if (loopFound) {
initPkt.handInLoopMatch(newNewPkt);
return true;
}
matchedPkt.popPathLink();
}
restorePktInportPerHop(matchedPkt, oldInPort);
}
} else {
if (!isFindLoop) {
// TODO - NEED
log.warn("no link connecting at device {}, port {}", currentDeviceId, instPort);
}
}
} else if (instPort.equals(PortNumber.IN_PORT)) {
// TODO - in the future,
// we may need to resolve this condition 1
log.warn("can not handle {} port now.", PortNumber.IN_PORT);
} else if (instPort.equals(PortNumber.NORMAL) || instPort.equals(PortNumber.FLOOD) || instPort.equals(PortNumber.ALL)) {
// TODO - in the future,
// we may need to resolve this condition 2
log.warn("can not handle {}/{}/{} now.", PortNumber.NORMAL, PortNumber.FLOOD, PortNumber.ALL);
}
return false;
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class OpticalPathIntentCompiler method reversePort.
/**
* Returns the PortNum of reverse port if annotation is present, otherwise return PortNum of the port itself.
* In the OpenROADM YANG models it is used the term "partner-port.
*
* @param portNumber the port
* @return the PortNum of reverse port if annotation is present, otherwise PortNum of the port itself.
*/
private PortNumber reversePort(DeviceId deviceId, PortNumber portNumber) {
Port port = deviceService.getPort(deviceId, portNumber);
String reversePort = port.annotations().value(OpticalPathIntent.REVERSE_PORT_ANNOTATION_KEY);
if (reversePort != null) {
PortNumber reversePortNumber = PortNumber.portNumber(reversePort);
return reversePortNumber;
} else {
return portNumber;
}
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class PortLoadBalancerManager method updatePortLoadBalancer.
private void updatePortLoadBalancer(PortLoadBalancer newPortLoadBalancer, PortLoadBalancer oldPortLoadBalancer) {
DeviceId deviceId = newPortLoadBalancer.portLoadBalancerId().deviceId();
if (!isLocalLeader(deviceId)) {
log.debug("Not the leader of {}. Skip updatePortLoadBalancer {}", deviceId, newPortLoadBalancer.portLoadBalancerId());
return;
}
portLoadBalancerProvExecutor.execute(() -> {
Integer nextid = Versioned.valueOrNull(portLoadBalancerNextStore.get(newPortLoadBalancer.portLoadBalancerId()));
if (nextid != null) {
// Compute modifications and context
PortLoadBalancerObjectiveContext context = new PortLoadBalancerObjectiveContext(newPortLoadBalancer.portLoadBalancerId());
Set<PortNumber> portsToBeAdded = Sets.difference(newPortLoadBalancer.ports(), oldPortLoadBalancer.ports());
Set<PortNumber> portsToBeRemoved = Sets.difference(oldPortLoadBalancer.ports(), newPortLoadBalancer.ports());
// and send them to the flowobj subsystem
if (!portsToBeAdded.isEmpty()) {
flowObjService.next(deviceId, nextObjBuilder(newPortLoadBalancer.portLoadBalancerId(), portsToBeAdded, nextid).addToExisting(context));
} else {
log.debug("NextObj for {} nothing to add", newPortLoadBalancer.portLoadBalancerId());
}
if (!portsToBeRemoved.isEmpty()) {
flowObjService.next(deviceId, nextObjBuilder(newPortLoadBalancer.portLoadBalancerId(), portsToBeRemoved, nextid).removeFromExisting(context));
} else {
log.debug("NextObj for {} nothing to remove", newPortLoadBalancer.portLoadBalancerId());
}
} else {
log.info("NextObj for {} does not exist. Skip updatePortLoadBalancer", newPortLoadBalancer.portLoadBalancerId());
}
});
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class PortLoadBalancerManager method onErrorHandler.
private void onErrorHandler(NextObjective nextObjective, PortLoadBalancerId portLoadBalancerId) {
// There was a failure
PortLoadBalancerData portLoadBalancerData = new PortLoadBalancerData(portLoadBalancerId);
// send FAILED event;
switch(nextObjective.op()) {
case ADD:
// If ADD is failing apps do not know the next id; let's update the store
portLoadBalancerNextStore.remove(portLoadBalancerId);
portLoadBalancerResStore.remove(portLoadBalancerId);
portLoadBalancerStore.remove(portLoadBalancerId);
post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.FAILED, portLoadBalancerData, portLoadBalancerData));
break;
case ADD_TO_EXISTING:
// If ADD_TO_EXISTING is failing let's remove the failed ports
Collection<PortNumber> addedPorts = nextObjective.next().stream().flatMap(t -> t.allInstructions().stream()).filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).collect(Collectors.toList());
portLoadBalancerStore.compute(portLoadBalancerId, (key, value) -> {
if (value != null && value.ports() != null && !value.ports().isEmpty()) {
value.ports().removeAll(addedPorts);
}
return value;
});
portLoadBalancerData.setNextId(nextObjective.id());
post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.FAILED, portLoadBalancerData, portLoadBalancerData));
break;
case REMOVE_FROM_EXISTING:
// If REMOVE_TO_EXISTING is failing let's re-add the failed ports
Collection<PortNumber> removedPorts = nextObjective.next().stream().flatMap(t -> t.allInstructions().stream()).filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).collect(Collectors.toList());
portLoadBalancerStore.compute(portLoadBalancerId, (key, value) -> {
if (value != null && value.ports() != null) {
value.ports().addAll(removedPorts);
}
return value;
});
portLoadBalancerData.setNextId(nextObjective.id());
post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.FAILED, portLoadBalancerData, portLoadBalancerData));
break;
case VERIFY:
case REMOVE:
// If ADD/REMOVE_TO_EXISTING, REMOVE and VERIFY are failing let's send
// also the info about the next id
portLoadBalancerData.setNextId(nextObjective.id());
post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.FAILED, portLoadBalancerData, portLoadBalancerData));
break;
default:
break;
}
}
Aggregations