qphamvan | 9aedb56 | 2019-02-19 14:38:53 +0100 | [diff] [blame] | 1 | /* |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame^] | 2 | * Copyright 2019-present Open Networking Foundation |
qphamvan | 9aedb56 | 2019-02-19 14:38:53 +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 | */ |
| 17 | |
| 18 | package org.onosproject.drivers.odtn; |
| 19 | |
qphamvan | 9aedb56 | 2019-02-19 14:38:53 +0100 | [diff] [blame] | 20 | import org.onlab.util.Frequency; |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame^] | 21 | import org.onosproject.drivers.odtn.openconfig.AbstractTerminalDeviceFlowRuleProgrammable; |
qphamvan | 9aedb56 | 2019-02-19 14:38:53 +0100 | [diff] [blame] | 22 | import org.onosproject.netconf.DatastoreId; |
qphamvan | 9aedb56 | 2019-02-19 14:38:53 +0100 | [diff] [blame] | 23 | import org.onosproject.netconf.NetconfException; |
| 24 | import org.onosproject.netconf.NetconfSession; |
| 25 | import org.slf4j.Logger; |
| 26 | import org.slf4j.LoggerFactory; |
| 27 | |
qphamvan | 9aedb56 | 2019-02-19 14:38:53 +0100 | [diff] [blame] | 28 | /** |
| 29 | * Implementation of FlowRuleProgrammable interface for |
| 30 | * OpenConfig terminal devices. |
| 31 | */ |
| 32 | public class NokiaFlowRuleProgrammable |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame^] | 33 | extends AbstractTerminalDeviceFlowRuleProgrammable { |
qphamvan | 9aedb56 | 2019-02-19 14:38:53 +0100 | [diff] [blame] | 34 | |
| 35 | private static final Logger log = |
| 36 | LoggerFactory.getLogger(NokiaFlowRuleProgrammable.class); |
| 37 | |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame^] | 38 | public void setOpticalChannelFrequency(NetconfSession session, |
qphamvan | 9aedb56 | 2019-02-19 14:38:53 +0100 | [diff] [blame] | 39 | String optChannel, Frequency freq) |
| 40 | throws NetconfException { |
Quan PHAM VAN | 84ac181 | 2019-02-28 16:22:45 +0100 | [diff] [blame] | 41 | String[] textStr = optChannel.split("-"); |
qphamvan | 9aedb56 | 2019-02-19 14:38:53 +0100 | [diff] [blame] | 42 | StringBuilder sb = new StringBuilder(); |
| 43 | sb.append( |
| 44 | "<components xmlns='http://openconfig.net/yang/platform'>" |
| 45 | + "<component operation='merge'>" |
Quan PHAM VAN | 84ac181 | 2019-02-28 16:22:45 +0100 | [diff] [blame] | 46 | + "<name>" + "OCH-" + textStr[1] + "-" + textStr[2] + "-" + textStr[3] + "</name>" |
qphamvan | 9aedb56 | 2019-02-19 14:38:53 +0100 | [diff] [blame] | 47 | + "<oc-opt-term:optical-channel " |
| 48 | + |
| 49 | " xmlns:oc-opt-term='http://openconfig.net/yang/terminal-device'>" |
| 50 | + " <oc-opt-term:config>" |
| 51 | + " <oc-opt-term:frequency>" + (long) freq.asMHz() + |
| 52 | "</oc-opt-term:frequency>" |
| 53 | + " </oc-opt-term:config>" |
| 54 | + " </oc-opt-term:optical-channel>" |
| 55 | + "</component>" |
| 56 | + "</components>"); |
| 57 | |
| 58 | boolean ok = |
| 59 | session.editConfig(DatastoreId.RUNNING, null, sb.toString()); |
| 60 | if (!ok) { |
| 61 | throw new NetconfException("error writing channel frequency"); |
| 62 | } |
| 63 | } |
| 64 | |
qphamvan | 9aedb56 | 2019-02-19 14:38:53 +0100 | [diff] [blame] | 65 | } |