blob: 0687758b2f8e6c20d28d8135757f58b5195840e7 [file] [log] [blame]
Ramon Casellas03f194f2018-11-15 16:06:02 +01001/*
Sudeep Desai6f136d42019-11-25 14:42:43 +05302 * Copyright 2019-present Open Networking Foundation
Ramon Casellas03f194f2018-11-15 16:06:02 +01003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15
16 * This work was partially supported by EC H2020 project METRO-HAUL (761727).
17 */
18
19package org.onosproject.drivers.odtn.openconfig;
20
Ramon Casellas03f194f2018-11-15 16:06:02 +010021import org.onlab.util.Frequency;
22import org.onosproject.drivers.odtn.impl.FlowRuleParser;
Ramon Casellas03f194f2018-11-15 16:06:02 +010023import org.onosproject.net.flow.FlowRule;
Ramon Casellas03f194f2018-11-15 16:06:02 +010024import org.onosproject.netconf.DatastoreId;
Ramon Casellas03f194f2018-11-15 16:06:02 +010025import org.onosproject.netconf.NetconfException;
26import org.onosproject.netconf.NetconfSession;
27import org.slf4j.Logger;
28import org.slf4j.LoggerFactory;
Ramon Casellas03f194f2018-11-15 16:06:02 +010029
Sudeep Desai6f136d42019-11-25 14:42:43 +053030public class TerminalDeviceFlowRuleProgrammable extends AbstractTerminalDeviceFlowRuleProgrammable {
Ramon Casellas03f194f2018-11-15 16:06:02 +010031
32 private static final Logger log =
33 LoggerFactory.getLogger(TerminalDeviceFlowRuleProgrammable.class);
34
Sudeep Desai6f136d42019-11-25 14:42:43 +053035 public void setOpticalChannelFrequency(NetconfSession session,
36 String optChannel, Frequency freq)
Ramon Casellas03f194f2018-11-15 16:06:02 +010037 throws NetconfException {
38 StringBuilder sb = new StringBuilder();
39 sb.append(
40 "<components xmlns='http://openconfig.net/yang/platform'>"
Boyuan Yan8f9f6ad2019-06-12 16:54:42 -070041 + "<component nc:operation='merge'>"
Ramon Casellas03f194f2018-11-15 16:06:02 +010042 + "<name>" + optChannel + "</name>"
43 + "<oc-opt-term:optical-channel "
44 +
45 " xmlns:oc-opt-term='http://openconfig.net/yang/terminal-device'>"
46 + " <oc-opt-term:config>"
47 + " <oc-opt-term:frequency>" + (long) freq.asMHz() +
48 "</oc-opt-term:frequency>"
49 + " </oc-opt-term:config>"
50 + " </oc-opt-term:optical-channel>"
51 + "</component>"
52 + "</components>");
Sudeep Desai6f136d42019-11-25 14:42:43 +053053 log.info("Optical Channel Frequency {}", sb.toString());
54 boolean ok = session.editConfig(DatastoreId.CANDIDATE, null, sb.toString());
Ramon Casellas03f194f2018-11-15 16:06:02 +010055 if (!ok) {
Sudeep Desai6f136d42019-11-25 14:42:43 +053056 throw new NetconfException("error committing channel frequency");
Ramon Casellas03f194f2018-11-15 16:06:02 +010057 }
58 }
59
60
Sudeep Desai6f136d42019-11-25 14:42:43 +053061 @Override
Andrea Campanellabb66e092019-01-28 13:50:06 +010062 protected String applyFlowRule(NetconfSession session, FlowRule r) throws NetconfException {
Ramon Casellas03f194f2018-11-15 16:06:02 +010063 FlowRuleParser frp = new FlowRuleParser(r);
64 if (!frp.isReceiver()) {
65 String optChannel = getOpticalChannel(session, frp.getPortNumber());
66 setOpticalChannelFrequency(session, optChannel,
Sudeep Desai6f136d42019-11-25 14:42:43 +053067 frp.getCentralFrequency());
Andrea Campanellabb66e092019-01-28 13:50:06 +010068 return optChannel + ":" + frp.getCentralFrequency().asGHz();
Ramon Casellas03f194f2018-11-15 16:06:02 +010069 }
Andrea Campanellabb66e092019-01-28 13:50:06 +010070 return String.valueOf(frp.getCentralFrequency().asGHz());
Ramon Casellas03f194f2018-11-15 16:06:02 +010071 }
72
Sudeep Desai6f136d42019-11-25 14:42:43 +053073 @Override
Andrea Campanellabb66e092019-01-28 13:50:06 +010074 protected String removeFlowRule(NetconfSession session, FlowRule r)
Ramon Casellas03f194f2018-11-15 16:06:02 +010075 throws NetconfException {
76 FlowRuleParser frp = new FlowRuleParser(r);
77 if (!frp.isReceiver()) {
78 String optChannel = getOpticalChannel(session, frp.getPortNumber());
79 setOpticalChannelFrequency(session, optChannel, Frequency.ofMHz(0));
Andrea Campanellabb66e092019-01-28 13:50:06 +010080 return optChannel + ":" + frp.getCentralFrequency().asGHz();
Ramon Casellas03f194f2018-11-15 16:06:02 +010081 }
Andrea Campanellabb66e092019-01-28 13:50:06 +010082 return String.valueOf(frp.getCentralFrequency().asGHz());
Ramon Casellas03f194f2018-11-15 16:06:02 +010083 }
84}