use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class LumentumSdnRoadmFlowRuleProgrammable method removeFlowRules.
@Override
public Collection<FlowRule> removeFlowRules(Collection<FlowRule> rules) {
try {
snmp = new LumentumSnmpDevice(data().deviceId());
} catch (IOException e) {
log.error("Failed to connect to device: ", e);
}
// Line ports
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(data().deviceId());
List<PortNumber> linePorts = ports.subList(ports.size() - 2, ports.size()).stream().map(p -> p.number()).collect(Collectors.toList());
// Apply the valid rules on the device
Collection<FlowRule> removed = rules.stream().map(r -> new CrossConnectFlowRule(r, linePorts)).filter(xc -> removeCrossConnect(xc)).collect(Collectors.toList());
// Remove flow rule from cache
CrossConnectCache cache = this.handler().get(CrossConnectCache.class);
removed.forEach(xc -> cache.remove(Objects.hash(data().deviceId(), xc.selector(), xc.treatment())));
return removed;
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class LumentumSdnRoadmFlowRuleProgrammable method applyFlowRules.
@Override
public Collection<FlowRule> applyFlowRules(Collection<FlowRule> rules) {
try {
snmp = new LumentumSnmpDevice(data().deviceId());
} catch (IOException e) {
log.error("Failed to connect to device: ", e);
}
// Line ports
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(data().deviceId());
List<PortNumber> linePorts = ports.subList(ports.size() - 2, ports.size()).stream().map(p -> p.number()).collect(Collectors.toList());
// Apply the valid rules on the device
Collection<FlowRule> added = rules.stream().map(r -> new CrossConnectFlowRule(r, linePorts)).filter(xc -> installCrossConnect(xc)).collect(Collectors.toList());
// Cache the cookie/priority
CrossConnectCache cache = this.handler().get(CrossConnectCache.class);
added.forEach(xc -> cache.set(Objects.hash(data().deviceId(), xc.selector(), xc.treatment()), xc.id(), xc.priority()));
return added;
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class LumentumSdnRoadmFlowRuleProgrammable method fetchRules.
// Returns the currently installed flow entries on the device.
private List<FlowRule> fetchRules(OID oid, boolean isAdd, PortNumber linePort) {
List<FlowRule> rules = new LinkedList<>();
for (TreeEvent event : snmp.get(oid)) {
if (event == null) {
continue;
}
VariableBinding[] varBindings = event.getVariableBindings();
for (VariableBinding varBinding : varBindings) {
CrossConnectCache cache = this.handler().get(CrossConnectCache.class);
if (varBinding.getVariable().toInt() == IN_SERVICE) {
int channel = varBinding.getOid().removeLast();
PortNumber addDropPort = getAddDropPort(channel, isAdd);
if (addDropPort == null) {
continue;
}
TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(isAdd ? addDropPort : linePort).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(toOchSignal(channel))).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(isAdd ? linePort : addDropPort).build();
// Lookup flow ID and priority
int hash = Objects.hash(data().deviceId(), selector, treatment);
Pair<FlowId, Integer> lookup = cache.get(hash);
if (lookup == null) {
continue;
}
FlowRule fr = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selector).withTreatment(treatment).withPriority(lookup.getRight()).withCookie(lookup.getLeft().value()).build();
rules.add(fr);
}
}
}
return rules;
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class TerminalDeviceDiscovery method parsePortComponent.
/**
* Parses a component XML doc into a PortDescription.
*
* @param component subtree to parse. It must be a component ot type PORT.
* @param components the full components tree, to cross-ref in
* case we need to check transceivers or optical channels.
*
* @return PortDescription or null if component does not have onos-index
*/
private PortDescription parsePortComponent(HierarchicalConfiguration component, HierarchicalConfiguration components) {
Map<String, String> annotations = new HashMap<>();
String name = component.getString("name");
String type = component.getString("state/type");
log.info("Parsing Component {} type {}", name, type);
annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, name);
annotations.put(OdtnDeviceDescriptionDiscovery.OC_TYPE, type);
// Store all properties as port properties
component.configurationsAt("properties/property").forEach(property -> {
String pn = property.getString("name");
String pv = property.getString("state/value");
annotations.put(pn, pv);
});
// Assing an ONOS port number
PortNumber portNum;
if (annotations.containsKey(ONOS_PORT_INDEX)) {
portNum = PortNumber.portNumber(Long.parseLong(annotations.get(ONOS_PORT_INDEX)));
} else {
log.warn("PORT {} does not include onos-index, hashing...", name);
portNum = PortNumber.portNumber(name.hashCode());
}
log.debug("PORT {} number {}", name, portNum);
// The heuristic to know if it is client or line side
if (!annotations.containsKey(PORT_TYPE)) {
if (hasTransceiverSubComponent(component, components)) {
annotations.put(PORT_TYPE, OdtnPortType.CLIENT.value());
} else if (hasOpticalChannelSubComponent(component, components)) {
annotations.put(PORT_TYPE, OdtnPortType.LINE.value());
}
}
// to be an issue with resource mapping
if (annotations.get(PORT_TYPE).equals(OdtnPortType.CLIENT.value())) {
log.debug("Adding CLIENT port");
Builder builder = DefaultPortDescription.builder();
builder.type(Type.PACKET);
builder.withPortNumber(portNum);
builder.annotations(DefaultAnnotations.builder().putAll(annotations).build());
return builder.build();
}
if (annotations.get(PORT_TYPE).equals(OdtnPortType.LINE.value())) {
log.debug("Adding LINE port");
// TODO: To be configured
OchSignal signalId = OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1);
return OchPortHelper.ochPortDescription(portNum, true, // TODO Client signal to be discovered
OduSignalType.ODU4, true, signalId, DefaultAnnotations.builder().putAll(annotations).build());
}
log.error("Unknown port type");
return null;
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class OpenConfigDeviceDiscovery method toPortDescriptionInternal.
/**
* Converts Component subtree to PortDescription.
*
* @param component subtree to parse
* @return PortDescription or null if component is not an ONOS Port
*/
private PortDescription toPortDescriptionInternal(HierarchicalConfiguration component) {
// to access other part of <data> tree:
// log.warn("parent data Node: {}",
// ((SubnodeConfiguration) component).getParent().getRootNode().getName());
Map<String, String> props = new HashMap<>();
String name = component.getString("name");
String type = component.getString("state/type");
checkNotNull(name, "name not found");
checkNotNull(type, "state/type not found");
props.put(OdtnDeviceDescriptionDiscovery.OC_NAME, name);
props.put(OdtnDeviceDescriptionDiscovery.OC_TYPE, type);
component.configurationsAt("properties/property").forEach(prop -> {
String pName = prop.getString("name");
String pValue = prop.getString("config/value");
props.put(pName, pValue);
});
PortNumber number = null;
if (!props.containsKey(ONOS_PORT_INDEX)) {
log.info("DEBUG: Component {} does not include onos-index, skipping", name);
// ODTN: port must have onos-index property
number = PortNumber.portNumber(COUNTER.getAndIncrement(), name);
} else {
number = PortNumber.portNumber(Long.parseLong(props.get(ONOS_PORT_INDEX)), name);
}
Builder builder = DefaultPortDescription.builder();
builder.withPortNumber(number);
switch(type) {
case "oc-platform-types:PORT":
case "PORT":
case "oc-opt-types:OPTICAL_CHANNEL":
case "OPTICAL CHANNEL":
// TODO assign appropriate port type & annotations at some point
// for now we just need a Port with annotations
builder.type(Type.OCH);
props.putIfAbsent(PORT_TYPE, OdtnPortType.LINE.value());
// Just a heuristics to deal with simple transponder
// if the device declare odtn-connection-id, just use them
// if not assign same value to relevant ports types
props.putIfAbsent(CONNECTION_ID, "the-only-one");
break;
case "oc-platform-types:TRANSCEIVER":
case "TRANSCEIVER":
// TODO assign appropriate port type & annotations at some point
// for now we just need a Port with annotations
builder.type(Type.PACKET);
props.putIfAbsent(PORT_TYPE, OdtnPortType.CLIENT.value());
// Just a heuristics to deal with simple transponder
// if the device declare odtn-connection-id, just use them
// if not assign same value to relevant ports types
props.putIfAbsent(CONNECTION_ID, "the-only-one");
break;
default:
log.info("DEBUG: Unknown component type {}", type);
return null;
}
builder.annotations(DefaultAnnotations.builder().putAll(props).build());
return builder.build();
}
Aggregations