blob: 36690a85bb047b9ae1bd3c52d5f12e20d94117fb [file] [log] [blame]
harjak47ff0db2019-10-08 10:30:47 +02001/*
Sudeep Desai6f136d42019-11-25 14:42:43 +05302 * Copyright 2019-present Open Networking Foundation
harjak47ff0db2019-10-08 10:30:47 +02003 *
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;
20
harjak47ff0db2019-10-08 10:30:47 +020021import org.onlab.util.Frequency;
Sudeep Desai6f136d42019-11-25 14:42:43 +053022import org.onosproject.drivers.odtn.openconfig.AbstractTerminalDeviceFlowRuleProgrammable;
harjak47ff0db2019-10-08 10:30:47 +020023import org.onosproject.netconf.DatastoreId;
harjak47ff0db2019-10-08 10:30:47 +020024import org.onosproject.netconf.NetconfException;
25import org.onosproject.netconf.NetconfSession;
26import org.slf4j.Logger;
27import org.slf4j.LoggerFactory;
28
harjak47ff0db2019-10-08 10:30:47 +020029/**
30 * Implementation of FlowRuleProgrammable interface for
31 * OpenConfig terminal devices.
32 */
33public class AdvaFlowRuleProgrammable
Sudeep Desai6f136d42019-11-25 14:42:43 +053034 extends AbstractTerminalDeviceFlowRuleProgrammable {
harjak47ff0db2019-10-08 10:30:47 +020035
36 private static final Logger log =
37 LoggerFactory.getLogger(AdvaFlowRuleProgrammable.class);
38
harjak47ff0db2019-10-08 10:30:47 +020039
Sudeep Desai6f136d42019-11-25 14:42:43 +053040 public void setOpticalChannelFrequency(NetconfSession session,
harjak47ff0db2019-10-08 10:30:47 +020041 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
harjak47ff0db2019-10-08 10:30:47 +020068
harjak47ff0db2019-10-08 10:30:47 +020069}