use of org.onlab.util.Frequency in project onos by opennetworkinglab.
the class RoadmCrossConnectCommand method createOchSignal.
/**
* This method forms parameters and creates and OchSignal instance from
* central frequency and the slot width of the channel.
* @param frequency - central frequency of the connection.
* @param sw - slot width of the optical channel.
* @param grid - frequency grid type.
* @param spacing - channel spacing.
* @return - returns created instance of OchSignal.
*/
protected OchSignal createOchSignal(String frequency, String sw, String grid, String spacing) {
Frequency centralFreq = Frequency.ofGHz(Double.parseDouble(frequency));
Frequency slotWidth = Frequency.ofGHz(Double.parseDouble(sw));
GridType gridType = null;
try {
gridType = GridType.valueOf(grid.toUpperCase());
} catch (Exception e) {
gridType = GridType.DWDM;
}
ChannelSpacing channelSpacing = null;
// It requires passing channelSpacing in the following format CHL_6P25GHZ or similar
try {
channelSpacing = ChannelSpacing.valueOf(spacing);
} catch (Exception e) {
channelSpacing = ChannelSpacing.CHL_50GHZ;
}
return OpticalChannelUtility.createOchSignal(centralFreq, slotWidth, gridType, channelSpacing);
}
use of org.onlab.util.Frequency in project onos by opennetworkinglab.
the class PolatisDeviceDescription method discoverPortDetails.
/**
* Discovers port details, for Polatis Snmp device.
*
* @return port list
*/
@Override
public List<PortDescription> discoverPortDetails() {
List<PortDescription> ports = Lists.newArrayList();
List<TableEvent> events;
DeviceId deviceId = handler().data().deviceId();
try {
OID[] columnOIDs = { new OID(PORT_CURRENT_STATE_OID) };
events = getTable(handler(), columnOIDs);
} catch (IOException e) {
log.error("Error reading ports table for device {} exception {}", deviceId, e);
return ports;
}
if (events == null) {
log.error("Error reading ports table for device {}", deviceId);
return ports;
}
for (TableEvent event : events) {
if (event == null) {
log.error("Error reading event for device {}", deviceId);
continue;
}
VariableBinding[] columns = event.getColumns();
if (columns == null) {
log.error("Error reading columns for device {} event {}", deviceId, event);
continue;
}
VariableBinding portColumn = columns[0];
if (portColumn == null) {
continue;
}
int port = event.getIndex().last();
boolean enabled = (portColumn.getVariable().toInt() == 1);
PortNumber portNumber = PortNumber.portNumber(port);
DefaultAnnotations annotations = DefaultAnnotations.builder().build();
double opticalBand = Spectrum.O_BAND_MIN.asGHz() - Spectrum.L_BAND_MAX.asGHz();
Frequency opticalGrid = Frequency.ofGHz(opticalBand / POLATIS_NUM_OF_WAVELENGTHS);
PortDescription p = omsPortDescription(portNumber, enabled, Spectrum.O_BAND_MIN, Spectrum.L_BAND_MAX, opticalGrid, annotations);
ports.add(p);
}
return ports;
}
use of org.onlab.util.Frequency in project onos by opennetworkinglab.
the class LumentumNetconfRoadmFlowRuleProgrammable method rpcAddConnection.
// Following Lumentum documentation rpc operation to configure a new connection
private boolean rpcAddConnection(LumentumFlowRule xc) {
Pair<Short, Short> pair = setModuleIdConnection(xc);
String module = pair.getLeft().toString();
String connectionId = pair.getRight().toString();
log.debug("Lumentum driver new connection sent moduleId {} connId {}", xc.getConnectionModule(), xc.getConnectionId());
// Conversion of ochSignal format (center frequency + diameter) to Lumentum frequency slot format (start - end)
Frequency freqRadius = Frequency.ofHz(xc.ochSignal().channelSpacing().frequency().asHz() / 2);
Frequency center = xc.ochSignal().centralFrequency();
String startFreq = String.valueOf(center.subtract(freqRadius).asHz() / GHZ);
String endFreq = String.valueOf(center.add(freqRadius).asHz() / GHZ);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" + "\n");
stringBuilder.append("<add-connection xmlns=\"http://www.lumentum.com/lumentum-ote-connection\">" + "\n");
stringBuilder.append("<dn>ne=1;chassis=1;card=1;module=" + module + ";connection=" + connectionId + "</dn>" + "\n");
stringBuilder.append("<start-freq>" + startFreq + "</start-freq>" + "\n");
stringBuilder.append("<end-freq>" + endFreq + "</end-freq>" + "\n");
stringBuilder.append("<attenuation>" + "0.0" + "</attenuation>" + "\n");
stringBuilder.append("<blocked>" + "false" + "</blocked>" + "\n");
stringBuilder.append("<maintenance-state>" + "in-service" + "</maintenance-state>" + "\n");
if (xc.isAddRule()) {
stringBuilder.append("<input-port-reference>" + DN_CARD1 + xc.addDrop().toString() + "</input-port-reference>" + "\n");
stringBuilder.append("<output-port-reference>" + DN_CARD1 + MUX_OUT + "</output-port-reference>" + "\n");
} else {
stringBuilder.append("<input-port-reference>" + DN_CARD1 + DEMUX_IN + "</input-port-reference>" + "\n");
stringBuilder.append("<output-port-reference>" + DN_CARD1 + xc.addDrop().toString() + "</output-port-reference>" + "\n");
}
stringBuilder.append("<custom-name>" + "onos-connection" + "</custom-name>" + "\n");
stringBuilder.append("</add-connection>" + "\n");
stringBuilder.append("</rpc>" + "\n");
log.info("Lumentum ROADM20 - RPC add-connection sent to device {}", did());
log.debug("Lumentum ROADM20 - RPC add-connection sent to device {} {}", did(), stringBuilder);
return editCrossConnect(stringBuilder.toString());
}
use of org.onlab.util.Frequency in project onos by opennetworkinglab.
the class ClientLineTerminalDeviceFlowRuleProgrammable method applyFlowRule.
/**
* Apply a single flowrule to the device.
*
* --- Directionality details:
* Driver supports ADD (INGRESS) and DROP (EGRESS) rules generated by OpticalCircuit/OpticalConnectivity intents
* the format of the rules are checked in class TerminalDeviceFlowRule
*
* However, the physical transponder is always bidirectional as specified in OpenConfig YANG models
* therefore ADD and DROP rules are mapped in the same xml that ENABLE (and tune) a transponder port.
*
* If the intent is generated as bidirectional both ADD and DROP flowrules are generated for each device, thus
* the same xml is sent twice to the device.
*
* @param session The Netconf session.
* @param rule Flow Rules to be applied.
* @return true if no Netconf errors are received from the device when xml is sent
* @throws NetconfException if exchange goes wrong
*/
protected boolean applyFlowRule(NetconfSession session, TerminalDeviceFlowRule rule) {
// --- enable the line port
if (rule.type == TerminalDeviceFlowRule.Type.LINE_INGRESS || rule.type == TerminalDeviceFlowRule.Type.LINE_EGRESS) {
FlowRuleParser frp = new FlowRuleParser(rule);
String componentName = frp.getPortNumber().toString();
Frequency centralFrequency = frp.getCentralFrequency();
StringBuilder componentConf = new StringBuilder();
log.info("Sending LINE FlowRule to device {} LINE port {}, frequency {}", did(), componentName, centralFrequency);
try {
setOpticalChannelFrequency(session, componentName, centralFrequency);
} catch (NetconfException e) {
log.error("Error writing central frequency in the component");
return false;
}
try {
setLogicalChannel(session, OPERATION_ENABLE, componentName);
} catch (NetconfException e) {
log.error("Error enabling the logical channel");
return false;
}
}
// TODO check the OTN mapping of client ports into the line port frame specified by parameter "<allocation>"
if (rule.type == TerminalDeviceFlowRule.Type.CLIENT_INGRESS || rule.type == TerminalDeviceFlowRule.Type.CLIENT_EGRESS) {
String clientPortName;
String linePortName;
if (rule.type == TerminalDeviceFlowRule.Type.CLIENT_INGRESS) {
clientPortName = rule.inPort().toString();
linePortName = rule.outPort().toString();
} else {
clientPortName = rule.outPort().toString();
linePortName = rule.inPort().toString();
}
log.info("Sending CLIENT FlowRule to device {} CLIENT port: {}, LINE port {}", did(), clientPortName, linePortName);
try {
setLogicalChannelAssignment(session, OPERATION_ENABLE, clientPortName, linePortName, DEFAULT_ASSIGNMENT_INDEX, DEFAULT_ALLOCATION_INDEX);
} catch (NetconfException e) {
log.error("Error setting the logical channel assignment");
return false;
}
}
return true;
}
use of org.onlab.util.Frequency in project onos by opennetworkinglab.
the class ClientLineTerminalDeviceFlowRuleProgrammable method fetchConnectionsFromDevice.
/**
* Fetches list of connections from device.
*
* TODO manage allow external flow rules (allowExternalFlowRules)
* Currently removes from the device all connections that are not currently present in the DeviceConnectionCache.
*
* @return connections that are present on the device and in the DeviceConnectionCache.
*/
private List<FlowRule> fetchConnectionsFromDevice() {
List<FlowRule> confirmedRules = new ArrayList<>();
String reply;
FlowRule cacheAddRule;
FlowRule cacheDropRule;
NetconfSession session = getNetconfSession();
// Get relevant information from the device
StringBuilder requestFilter = new StringBuilder();
requestFilter.append("<components xmlns='http://openconfig.net/yang/platform'>");
requestFilter.append(" <component>");
requestFilter.append(" <name/>");
requestFilter.append(" <oc-opt-term:optical-channel " + "xmlns:oc-opt-term='http://openconfig.net/yang/terminal-device'>");
requestFilter.append(" <oc-opt-term:config/>");
requestFilter.append(" </oc-opt-term:optical-channel>");
requestFilter.append(" </component>");
requestFilter.append("</components>");
requestFilter.append("<terminal-device xmlns='http://openconfig.net/yang/terminal-device'>");
requestFilter.append(" <logical-channels>");
requestFilter.append(" <channel>");
requestFilter.append(" <index/>");
requestFilter.append(" <config>");
requestFilter.append(" <admin-state/>");
requestFilter.append(" <logical-channel-type/>");
requestFilter.append(" </config>");
requestFilter.append(" <logical-channel-assignments>");
requestFilter.append(" <assignment>");
requestFilter.append(" <config>");
requestFilter.append(" <logical-channel/>");
requestFilter.append(" </config>");
requestFilter.append(" </assignment>");
requestFilter.append(" </logical-channel-assignments>");
requestFilter.append(" </channel>");
requestFilter.append(" </logical-channels>");
requestFilter.append("</terminal-device>");
try {
reply = session.get(requestFilter.toString(), null);
// log.debug("TRANSPONDER CONNECTIONS - fetchConnectionsFromDevice {} reply {}", did(), reply);
} catch (NetconfException e) {
log.error("Failed to retrieve configuration details for device {}", handler().data().deviceId(), e);
return ImmutableList.of();
}
HierarchicalConfiguration cfg = XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes()));
List<HierarchicalConfiguration> logicalChannels = cfg.configurationsAt("data.terminal-device.logical-channels.channel");
List<HierarchicalConfiguration> components = cfg.configurationsAt("data.components.component");
// Retrieve the ENABLED line ports
List<String> enabledOpticalChannels = logicalChannels.stream().filter(r -> r.getString("config.logical-channel-type").equals(OC_TYPE_PROT_OTN)).filter(r -> r.getString("config.admin-state").equals(OPERATION_ENABLE)).map(r -> r.getString("index")).collect(Collectors.toList());
log.debug("fetchConnectionsFromDevice {} enabledOpticalChannelsIndex {}", did(), enabledOpticalChannels);
if (enabledOpticalChannels.size() != 0) {
for (String channel : enabledOpticalChannels) {
log.debug("fetchOpticalConnectionsFromDevice {} channel {}", did(), channel);
// Retrieve the corresponding central frequency from the associated component
// TODO correlate the components instead of relying on naming
Frequency centralFreq = components.stream().filter(c -> c.getString("name").equals(PREFIX_CHANNEL + channel)).map(c -> c.getDouble("optical-channel.config.frequency")).map(c -> Frequency.ofMHz(c)).findFirst().orElse(null);
confirmedRules.addAll(fetchLineConnectionFromDevice(channel, centralFreq));
}
}
// Retrieve the ENABLED client ports
List<String> enabledClientChannels = logicalChannels.stream().filter(r -> r.getString("config.logical-channel-type").equals(OC_TYPE_PROT_ETH)).filter(r -> r.getString("config.admin-state").equals(OPERATION_ENABLE)).map(r -> r.getString("index")).collect(Collectors.toList());
log.debug("fetchClientConnectionsFromDevice {} enabledClientChannelsIndex {}", did(), enabledClientChannels);
if (enabledClientChannels.size() != 0) {
for (String clientPort : enabledClientChannels) {
log.debug("fetchClientConnectionsFromDevice {} channel {}", did(), clientPort);
String linePort = logicalChannels.stream().filter(r -> r.getString("config.logical-channel-type").equals(OC_TYPE_PROT_ETH)).filter(r -> r.getString("config.admin-state").equals(OPERATION_ENABLE)).filter(r -> r.getString("index").equals(clientPort)).map(r -> r.getString("logical-channel-assignments.assignment.config.logical-channel")).findFirst().orElse(null);
// Build the corresponding flow rule as expected
// Selector including port
// Treatment including port
PortNumber clientPortNumber = PortNumber.portNumber(clientPort);
PortNumber linePortNumber = PortNumber.portNumber(linePort);
confirmedRules.addAll(fetchClientConnectionFromDevice(clientPortNumber, linePortNumber));
}
}
// Returns rules that are both on the device and on the cache
if (confirmedRules.size() != 0) {
log.info("fetchConnectionsFromDevice {} number of confirmed rules {}", did(), confirmedRules.size());
return confirmedRules;
} else {
return ImmutableList.of();
}
}
Aggregations