harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 1 | /* |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame^] | 2 | * Copyright 2019-present Open Networking Foundation |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [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; |
| 20 | |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 21 | import org.onlab.util.Frequency; |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame^] | 22 | import org.onosproject.drivers.odtn.openconfig.AbstractTerminalDeviceFlowRuleProgrammable; |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 23 | import org.onosproject.netconf.DatastoreId; |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 24 | import org.onosproject.netconf.NetconfException; |
| 25 | import org.onosproject.netconf.NetconfSession; |
| 26 | import org.slf4j.Logger; |
| 27 | import org.slf4j.LoggerFactory; |
| 28 | |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 29 | /** |
| 30 | * Implementation of FlowRuleProgrammable interface for |
| 31 | * OpenConfig terminal devices. |
| 32 | */ |
| 33 | public class AdvaFlowRuleProgrammable |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame^] | 34 | extends AbstractTerminalDeviceFlowRuleProgrammable { |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 35 | |
| 36 | private static final Logger log = |
| 37 | LoggerFactory.getLogger(AdvaFlowRuleProgrammable.class); |
| 38 | |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 39 | |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame^] | 40 | public void setOpticalChannelFrequency(NetconfSession session, |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 41 | String optChannel, Frequency freq) |
| 42 | throws NetconfException { |
| 43 | StringBuilder sb = new StringBuilder(); |
| 44 | sb.append( |
| 45 | "<components xmlns='http://openconfig.net/yang/platform'>" |
| 46 | + "<component>" |
| 47 | + "<config>" |
| 48 | + "<name>" + optChannel + "</name>" |
| 49 | + "</config>" |
| 50 | + "<optical-channel xmlns='http://openconfig.net/yang/terminal-device'>" |
| 51 | + "<config>" |
| 52 | + "<frequency>" + (long) freq.asMHz() + "</frequency>" |
| 53 | + "</config>" |
| 54 | + "</optical-channel>" |
| 55 | + "</component>" |
| 56 | + "</components>"); |
| 57 | log.info("Optical Channel Frequency {}", sb.toString()); |
| 58 | boolean ok = session.editConfig(DatastoreId.RUNNING, null, sb.toString()); |
| 59 | if (!ok) { |
| 60 | throw new NetconfException("error writing channel frequency"); |
| 61 | } |
| 62 | ok = session.commit(); |
| 63 | if (!ok) { |
| 64 | throw new NetconfException("error committing channel frequency"); |
| 65 | } |
| 66 | } |
| 67 | |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 68 | |
harjak | 47ff0db | 2019-10-08 10:30:47 +0200 | [diff] [blame] | 69 | } |