Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 1 | /* |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame^] | 2 | * Copyright 2019-present Open Networking Foundation |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 3 | * |
| 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 | |
| 19 | package org.onosproject.drivers.odtn.openconfig; |
| 20 | |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 21 | import org.onlab.util.Frequency; |
| 22 | import org.onosproject.drivers.odtn.impl.FlowRuleParser; |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 23 | import org.onosproject.net.flow.FlowRule; |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 24 | import org.onosproject.netconf.DatastoreId; |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 25 | import org.onosproject.netconf.NetconfException; |
| 26 | import org.onosproject.netconf.NetconfSession; |
| 27 | import org.slf4j.Logger; |
| 28 | import org.slf4j.LoggerFactory; |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 29 | |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame^] | 30 | public class TerminalDeviceFlowRuleProgrammable extends AbstractTerminalDeviceFlowRuleProgrammable { |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 31 | |
| 32 | private static final Logger log = |
| 33 | LoggerFactory.getLogger(TerminalDeviceFlowRuleProgrammable.class); |
| 34 | |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame^] | 35 | public void setOpticalChannelFrequency(NetconfSession session, |
| 36 | String optChannel, Frequency freq) |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 37 | throws NetconfException { |
| 38 | StringBuilder sb = new StringBuilder(); |
| 39 | sb.append( |
| 40 | "<components xmlns='http://openconfig.net/yang/platform'>" |
Boyuan Yan | 8f9f6ad | 2019-06-12 16:54:42 -0700 | [diff] [blame] | 41 | + "<component nc:operation='merge'>" |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 42 | + "<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 Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame^] | 53 | log.info("Optical Channel Frequency {}", sb.toString()); |
| 54 | boolean ok = session.editConfig(DatastoreId.CANDIDATE, null, sb.toString()); |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 55 | if (!ok) { |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame^] | 56 | throw new NetconfException("error committing channel frequency"); |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | |
| 60 | |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame^] | 61 | @Override |
Andrea Campanella | bb66e09 | 2019-01-28 13:50:06 +0100 | [diff] [blame] | 62 | protected String applyFlowRule(NetconfSession session, FlowRule r) throws NetconfException { |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 63 | FlowRuleParser frp = new FlowRuleParser(r); |
| 64 | if (!frp.isReceiver()) { |
| 65 | String optChannel = getOpticalChannel(session, frp.getPortNumber()); |
| 66 | setOpticalChannelFrequency(session, optChannel, |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame^] | 67 | frp.getCentralFrequency()); |
Andrea Campanella | bb66e09 | 2019-01-28 13:50:06 +0100 | [diff] [blame] | 68 | return optChannel + ":" + frp.getCentralFrequency().asGHz(); |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 69 | } |
Andrea Campanella | bb66e09 | 2019-01-28 13:50:06 +0100 | [diff] [blame] | 70 | return String.valueOf(frp.getCentralFrequency().asGHz()); |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 71 | } |
| 72 | |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame^] | 73 | @Override |
Andrea Campanella | bb66e09 | 2019-01-28 13:50:06 +0100 | [diff] [blame] | 74 | protected String removeFlowRule(NetconfSession session, FlowRule r) |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 75 | 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 Campanella | bb66e09 | 2019-01-28 13:50:06 +0100 | [diff] [blame] | 80 | return optChannel + ":" + frp.getCentralFrequency().asGHz(); |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 81 | } |
Andrea Campanella | bb66e09 | 2019-01-28 13:50:06 +0100 | [diff] [blame] | 82 | return String.valueOf(frp.getCentralFrequency().asGHz()); |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 83 | } |
| 84 | } |