use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class ECDeviceStore method updatePortStatistics.
@Override
public DeviceEvent updatePortStatistics(ProviderId providerId, DeviceId deviceId, Collection<PortStatistics> newStatsCollection) {
Map<PortNumber, PortStatistics> prvStatsMap = devicePortStats.get(deviceId);
Map<PortNumber, PortStatistics> newStatsMap = Maps.newHashMap();
Map<PortNumber, PortStatistics> deltaStatsMap = Maps.newHashMap();
if (prvStatsMap != null) {
for (PortStatistics newStats : newStatsCollection) {
PortNumber port = newStats.portNumber();
PortStatistics prvStats = prvStatsMap.get(port);
DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder();
PortStatistics deltaStats = builder.build();
if (prvStats != null) {
deltaStats = calcDeltaStats(deviceId, prvStats, newStats);
}
deltaStatsMap.put(port, deltaStats);
newStatsMap.put(port, newStats);
}
} else {
for (PortStatistics newStats : newStatsCollection) {
PortNumber port = newStats.portNumber();
newStatsMap.put(port, newStats);
}
}
devicePortDeltaStats.put(deviceId, deltaStatsMap);
devicePortStats.put(deviceId, newStatsMap);
// DeviceEvent returns null because of InternalPortStatsListener usage
return null;
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class ECDeviceStore method refreshDevicePortCache.
private List<DeviceEvent> refreshDevicePortCache(ProviderId providerId, DeviceId deviceId, Optional<PortNumber> portNumber) {
Device device = devices.get(deviceId);
checkArgument(device != null, DEVICE_NOT_FOUND, deviceId);
List<DeviceEvent> events = Lists.newArrayList();
Map<PortNumber, Port> ports = devicePorts.computeIfAbsent(deviceId, key -> Maps.newConcurrentMap());
List<PortDescription> descriptions = Lists.newArrayList();
portDescriptions.entrySet().forEach(e -> {
PortKey key = e.getKey();
PortDescription value = e.getValue();
if (key.deviceId().equals(deviceId) && key.providerId().equals(providerId)) {
if (portNumber.isPresent()) {
if (portNumber.get().equals(key.portNumber())) {
descriptions.add(value);
}
} else {
descriptions.add(value);
}
}
});
for (PortDescription description : descriptions) {
final PortNumber number = description.portNumber();
ports.compute(number, (k, existingPort) -> {
Port newPort = composePort(device, number);
if (existingPort == null) {
events.add(new DeviceEvent(PORT_ADDED, device, newPort));
} else {
if (existingPort.isEnabled() != newPort.isEnabled() || existingPort.type() != newPort.type() || existingPort.portSpeed() != newPort.portSpeed() || !AnnotationsUtil.isEqual(existingPort.annotations(), newPort.annotations())) {
events.add(new DeviceEvent(PORT_UPDATED, device, newPort));
}
}
return newPort;
});
}
return events;
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class ClientLineTerminalDeviceFlowRuleProgrammable method fetchLineConnectionFromDevice.
private List<FlowRule> fetchLineConnectionFromDevice(String channel, Frequency centralFreq) {
List<FlowRule> confirmedRules = new ArrayList<>();
FlowRule cacheAddRule;
FlowRule cacheDropRule;
NetconfSession session = getNetconfSession();
log.debug("fetchOpticalConnectionsFromDevice {} frequency {}", did(), centralFreq);
// Build the corresponding flow rule as expected
// Selector including port and ochSignal
// Treatment including port
PortNumber inputPortNumber = PortNumber.portNumber(channel);
PortNumber outputPortNumber = PortNumber.portNumber(channel);
log.debug("fetchOpticalConnectionsFromDevice {} port {}-{}", did(), inputPortNumber, outputPortNumber);
TrafficSelector selectorDrop = DefaultTrafficSelector.builder().matchInPort(inputPortNumber).add(Criteria.matchLambda(toOchSignal(centralFreq, 50.0))).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).build();
TrafficTreatment treatmentDrop = DefaultTrafficTreatment.builder().setOutput(outputPortNumber).build();
TrafficSelector selectorAdd = DefaultTrafficSelector.builder().matchInPort(inputPortNumber).build();
TrafficTreatment treatmentAdd = DefaultTrafficTreatment.builder().add(Instructions.modL0Lambda(toOchSignal(centralFreq, 50.0))).setOutput(outputPortNumber).build();
// Retrieved rules and cached rules are considered equal if both selector and treatment are equal
cacheAddRule = null;
cacheDropRule = null;
if (getConnectionCache().size(did()) != 0) {
cacheDropRule = getConnectionCache().get(did()).stream().filter(r -> (r.selector().equals(selectorDrop) && r.treatment().equals(treatmentDrop))).findFirst().orElse(null);
cacheAddRule = getConnectionCache().get(did()).stream().filter(r -> (r.selector().equals(selectorAdd) && r.treatment().equals(treatmentAdd))).findFirst().orElse(null);
}
// Include the DROP rule to the retrieved rules if found in cache
if ((cacheDropRule != null)) {
confirmedRules.add(cacheDropRule);
log.debug("fetchOpticalConnectionsFromDevice {} DROP LINE rule included in the cache {}", did(), cacheDropRule);
} else {
log.warn("fetchOpticalConnectionsFromDevice {} DROP LINE rule not included in cache", did());
}
// Include the ADD rule to the retrieved rules if found in cache
if ((cacheAddRule != null)) {
confirmedRules.add(cacheAddRule);
log.debug("fetchOpticalConnectionsFromDevice {} ADD LINE rule included in the cache {}", did(), cacheAddRule.selector());
} else {
log.warn("fetchOpticalConnectionsFromDevice {} ADD LINE rule not included in cache", did());
}
// If neither Add or Drop rules are present in the cache, remove configuration from the device
if ((cacheDropRule == null) && (cacheAddRule == null)) {
log.warn("fetchOpticalConnectionsFromDevice {} ADD and DROP rule not included in the cache", did());
FlowRule deviceDropRule = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selectorDrop).withTreatment(treatmentDrop).withCookie(DEFAULT_RULE_COOKIE).withPriority(DEFAULT_RULE_PRIORITY).build();
FlowRule deviceAddRule = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selectorAdd).withTreatment(treatmentAdd).withCookie(DEFAULT_RULE_COOKIE).withPriority(DEFAULT_RULE_PRIORITY).build();
try {
// TODO this is not required if allowExternalFlowRules
TerminalDeviceFlowRule addRule = new TerminalDeviceFlowRule(deviceAddRule, getLinePorts());
removeFlowRule(session, addRule);
TerminalDeviceFlowRule dropRule = new TerminalDeviceFlowRule(deviceDropRule, getLinePorts());
removeFlowRule(session, dropRule);
} catch (NetconfException e) {
openConfigError("Error removing LINE rule from device", e);
}
}
return confirmedRules;
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class ClientLineTerminalDeviceFlowRuleProgrammable method fetchClientConnectionFromDevice.
private List<FlowRule> fetchClientConnectionFromDevice(PortNumber clientPortNumber, PortNumber linePortNumber) {
List<FlowRule> confirmedRules = new ArrayList<>();
FlowRule cacheAddRule;
FlowRule cacheDropRule;
NetconfSession session = getNetconfSession();
// Build the corresponding flow rule as expected
// Selector including port
// Treatment including port
log.debug("fetchClientConnectionsFromDevice {} client {} line {}", did(), clientPortNumber, linePortNumber);
TrafficSelector selectorDrop = DefaultTrafficSelector.builder().matchInPort(linePortNumber).build();
TrafficTreatment treatmentDrop = DefaultTrafficTreatment.builder().setOutput(clientPortNumber).build();
TrafficSelector selectorAdd = DefaultTrafficSelector.builder().matchInPort(clientPortNumber).build();
TrafficTreatment treatmentAdd = DefaultTrafficTreatment.builder().setOutput(linePortNumber).build();
// Retrieved rules and cached rules are considered equal if both selector and treatment are equal
cacheAddRule = null;
cacheDropRule = null;
if (getConnectionCache().size(did()) != 0) {
cacheDropRule = getConnectionCache().get(did()).stream().filter(r -> (r.selector().equals(selectorDrop) && r.treatment().equals(treatmentDrop))).findFirst().orElse(null);
cacheAddRule = getConnectionCache().get(did()).stream().filter(r -> (r.selector().equals(selectorAdd) && r.treatment().equals(treatmentAdd))).findFirst().orElse(null);
}
// Include the DROP rule to the retrieved rules if found in cache
if ((cacheDropRule != null)) {
confirmedRules.add(cacheDropRule);
log.debug("fetchClientConnectionsFromDevice {} DROP CLIENT rule in the cache {}", did(), cacheDropRule);
} else {
log.warn("fetchClientConnectionsFromDevice {} DROP CLIENT rule not found in cache", did());
}
// Include the ADD rule to the retrieved rules if found in cache
if ((cacheAddRule != null)) {
confirmedRules.add(cacheAddRule);
log.debug("fetchClientConnectionsFromDevice {} ADD CLIENT rule in the cache {}", did(), cacheAddRule);
} else {
log.warn("fetchClientConnectionsFromDevice {} ADD CLIENT rule not found in cache", did());
}
if ((cacheDropRule == null) && (cacheAddRule == null)) {
log.warn("fetchClientConnectionsFromDevice {} ADD and DROP rule not included in the cache", did());
FlowRule deviceDropRule = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selectorDrop).withTreatment(treatmentDrop).withCookie(DEFAULT_RULE_COOKIE).withPriority(DEFAULT_RULE_PRIORITY).build();
FlowRule deviceAddRule = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selectorAdd).withTreatment(treatmentAdd).withCookie(DEFAULT_RULE_COOKIE).withPriority(DEFAULT_RULE_PRIORITY).build();
try {
// TODO this is not required if allowExternalFlowRules
TerminalDeviceFlowRule addRule = new TerminalDeviceFlowRule(deviceAddRule, getLinePorts());
removeFlowRule(session, addRule);
TerminalDeviceFlowRule dropRule = new TerminalDeviceFlowRule(deviceDropRule, getLinePorts());
removeFlowRule(session, dropRule);
} catch (NetconfException e) {
openConfigError("Error removing CLIENT rule from device", e);
}
}
return confirmedRules;
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class LumentumNetconfRoadmDiscovery method parseLumentumRoadmPorts.
/**
* Parses a configuration and returns a set of ports.
*
* @param cfg a hierarchical configuration
* @return a list of port descriptions
*/
protected List<PortDescription> parseLumentumRoadmPorts(HierarchicalConfiguration cfg) {
List<PortDescription> portDescriptions = Lists.newArrayList();
List<HierarchicalConfiguration> ports = cfg.configurationsAt(PHYSICAL_PORT);
ports.stream().forEach(pcfg -> {
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
// Load port number
PortNumber portNum = PortNumber.portNumber(pcfg.getString(DN).substring(pcfg.getString(DN).lastIndexOf(DN_PORT) + 5));
// Load port state
String maintenanceState = pcfg.getString(MAINTENANCE_STATE);
boolean isEnabled = ((maintenanceState != null) && (maintenanceState).equals(IN_SERVICE));
// Load port type (FIBER/COPPER)
Port.Type type = null;
for (Object o : pcfg.getList(PORT_EXTENSION)) {
String s = (String) o;
if (s.contains(OPTICAL_INPUT) || s.contains(OPTICAL_OUTPUT)) {
type = Port.Type.FIBER;
log.debug("Loaded OPTICAL port {}", portNum);
} else if (s.contains(PORT_ETHERNET) || s.contains(PORT_PLUGGABLE)) {
type = Port.Type.COPPER;
log.debug("Loaded PACKET port {}", portNum);
}
}
// Load port speed of Ethernet interface, expressed in Mb/s
// should be the speed of optical port
Long speed = 0L;
if (type != null) {
if (type.equals(Port.Type.COPPER)) {
String speedString = pcfg.getString(PORT_SPEED);
log.debug("--- port {} loaded speed {}", portNum, speedString);
if (speedString != null) {
if (speedString.contains("Mb")) {
speed = Long.parseLong(speedString.substring(speedString.lastIndexOf("speed_") + 6, speedString.lastIndexOf("Mb")));
}
if (speedString.contains("Gb")) {
speed = 1000 * Long.parseLong(speedString.substring(speedString.lastIndexOf("speed_") + 6, speedString.lastIndexOf("Gb")));
}
} else {
log.error("Lumentum NETCONF - Port speed of Ethernet port not correctly loaded");
}
}
} else {
log.error("Port Type not correctly loaded");
}
/**
* Setting the reverse port value for the unidirectional ports.
*
* In this device each port includes an input fiber and an output fiber.
* The 20 input fibers are numbered from MIN_MUX_PORT = 4101 to MAX_MUX_PORT = 4120.
* The 20 output fibers are numbered from MIN_DEM_PORT = 5201 to MAX_DEM_PORT = 5220.
*
* Where port 520x is always the reverse of 410x.
*/
if ((portNum.toLong() >= MIN_MUX_PORT) && (portNum.toLong() <= MAX_MUX_PORT)) {
Long reversePortId = portNum.toLong() + DELTA_MUX_DEM_PORT;
annotations.set(OpticalPathIntent.REVERSE_PORT_ANNOTATION_KEY, reversePortId.toString());
}
if ((portNum.toLong() >= MIN_DEM_PORT) && (portNum.toLong() <= MAX_DEM_PORT)) {
Long reversePortId = portNum.toLong() - DELTA_MUX_DEM_PORT;
annotations.set(OpticalPathIntent.REVERSE_PORT_ANNOTATION_KEY, reversePortId.toString());
}
// Load other information
pcfg.getKeys().forEachRemaining(k -> {
if (!k.contains(DN) && !k.contains(PORT_SPEED) && !k.contains(PORT_EXTENSION) && !k.contains(MAINTENANCE_STATE)) {
String value = pcfg.getString(k);
if (!value.isEmpty()) {
k = StringUtils.replaceEach(k, new String[] { "loteeth:", "lotep:", "lotepopt:", "config.", "=", ":", "state." }, new String[] { "", "", "", "", "", "", "" });
annotations.set(k, value);
// To visualize port name in the ROADM app GUI
if (k.equals(PORT_NAME)) {
annotations.set(AnnotationKeys.PORT_NAME, value);
}
}
}
});
log.debug("Lumentum NETCONF - retrieved port {},{},{},{},{}", portNum, isEnabled, type, speed, annotations.build());
if ((type == Port.Type.FIBER) && ((annotations.build().value(AnnotationKeys.PORT_NAME)).contains(MUX_PORT_NAME) || (annotations.build().value(AnnotationKeys.PORT_NAME)).contains(DEMUX_PORT_NAME) || (annotations.build().value(AnnotationKeys.PORT_NAME)).contains(LINE_PORT_NAME))) {
// These are the ports supporting OchSignals
portDescriptions.add(omsPortDescription(portNum, isEnabled, START_CENTER_FREQ_50, END_CENTER_FREQ_50, CHANNEL_SPACING_50.frequency(), annotations.build()));
} else {
// These are COPPER ports, or FIBER ports not supporting OchSignals
DefaultPortDescription.Builder portDescriptionBuilder = DefaultPortDescription.builder();
portDescriptionBuilder.withPortNumber(portNum).isEnabled(isEnabled).type(type).portSpeed(speed).annotations(annotations.build());
portDescriptions.add(portDescriptionBuilder.build());
}
});
return portDescriptions;
}
Aggregations