hiroki | 337c552 | 2019-01-20 20:05:51 -0800 | [diff] [blame] | 1 | /* |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame] | 2 | * Copyright 2019-present Open Networking Foundation |
hiroki | 337c552 | 2019-01-20 20:05:51 -0800 | [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 | |
hiroki | 337c552 | 2019-01-20 20:05:51 -0800 | [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; |
hiroki | 337c552 | 2019-01-20 20:05:51 -0800 | [diff] [blame] | 23 | import org.onosproject.netconf.DatastoreId; |
hiroki | 337c552 | 2019-01-20 20:05:51 -0800 | [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 | |
hiroki | 337c552 | 2019-01-20 20:05:51 -0800 | [diff] [blame] | 29 | /** |
| 30 | * Implementation of FlowRuleProgrammable interface for |
| 31 | * OpenConfig terminal devices. |
| 32 | */ |
| 33 | public class CassiniFlowRuleProgrammable |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame] | 34 | extends AbstractTerminalDeviceFlowRuleProgrammable { |
hiroki | 337c552 | 2019-01-20 20:05:51 -0800 | [diff] [blame] | 35 | |
| 36 | private static final Logger log = |
| 37 | LoggerFactory.getLogger(CassiniFlowRuleProgrammable.class); |
| 38 | |
hiroki | 337c552 | 2019-01-20 20:05:51 -0800 | [diff] [blame] | 39 | |
Sudeep Desai | 6f136d4 | 2019-11-25 14:42:43 +0530 | [diff] [blame] | 40 | public void setOpticalChannelFrequency(NetconfSession session, |
hiroki | 337c552 | 2019-01-20 20:05:51 -0800 | [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'>" |
Boyuan Yan | 8f9f6ad | 2019-06-12 16:54:42 -0700 | [diff] [blame] | 46 | + "<component nc:operation='merge'>" |
hiroki | 337c552 | 2019-01-20 20:05:51 -0800 | [diff] [blame] | 47 | + "<name>" + optChannel + "</name>" |
| 48 | + "<oc-opt-term:optical-channel " |
| 49 | + |
| 50 | " xmlns:oc-opt-term='http://openconfig.net/yang/terminal-device'>" |
| 51 | + " <oc-opt-term:config>" |
| 52 | + " <oc-opt-term:frequency>" + (long) freq.asMHz() + |
| 53 | "</oc-opt-term:frequency>" |
| 54 | + " </oc-opt-term:config>" |
| 55 | + " </oc-opt-term:optical-channel>" |
| 56 | + "</component>" |
| 57 | + "</components>"); |
Andrea Campanella | 3a36145 | 2019-08-02 10:17:53 +0200 | [diff] [blame] | 58 | log.info("Optical Channel Frequency {}", sb.toString()); |
| 59 | boolean ok = session.editConfig(DatastoreId.CANDIDATE, null, sb.toString()); |
hiroki | 337c552 | 2019-01-20 20:05:51 -0800 | [diff] [blame] | 60 | if (!ok) { |
| 61 | throw new NetconfException("error writing channel frequency"); |
| 62 | } |
Andrea Campanella | 3a36145 | 2019-08-02 10:17:53 +0200 | [diff] [blame] | 63 | ok = session.commit(); |
| 64 | if (!ok) { |
| 65 | throw new NetconfException("error committing channel frequency"); |
| 66 | } |
hiroki | 337c552 | 2019-01-20 20:05:51 -0800 | [diff] [blame] | 67 | } |
| 68 | |
hiroki | 337c552 | 2019-01-20 20:05:51 -0800 | [diff] [blame] | 69 | } |