blob: 774efca0bdd2d74016df1df38ebd47f69e1d6105 [file] [log] [blame]
hiroki337c5522019-01-20 20:05:51 -08001/*
Sudeep Desai6f136d42019-11-25 14:42:43 +05302 * Copyright 2019-present Open Networking Foundation
hiroki337c5522019-01-20 20:05:51 -08003 *
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
hiroki337c5522019-01-20 20:05:51 -080021import org.onlab.util.Frequency;
Sudeep Desai6f136d42019-11-25 14:42:43 +053022import org.onosproject.drivers.odtn.openconfig.AbstractTerminalDeviceFlowRuleProgrammable;
hiroki337c5522019-01-20 20:05:51 -080023import org.onosproject.netconf.DatastoreId;
hiroki337c5522019-01-20 20:05:51 -080024import org.onosproject.netconf.NetconfException;
25import org.onosproject.netconf.NetconfSession;
26import org.slf4j.Logger;
27import org.slf4j.LoggerFactory;
28
hiroki337c5522019-01-20 20:05:51 -080029/**
30 * Implementation of FlowRuleProgrammable interface for
31 * OpenConfig terminal devices.
32 */
33public class CassiniFlowRuleProgrammable
Sudeep Desai6f136d42019-11-25 14:42:43 +053034 extends AbstractTerminalDeviceFlowRuleProgrammable {
hiroki337c5522019-01-20 20:05:51 -080035
36 private static final Logger log =
37 LoggerFactory.getLogger(CassiniFlowRuleProgrammable.class);
38
hiroki337c5522019-01-20 20:05:51 -080039
Sudeep Desai6f136d42019-11-25 14:42:43 +053040 public void setOpticalChannelFrequency(NetconfSession session,
hiroki337c5522019-01-20 20:05:51 -080041 String optChannel, Frequency freq)
42 throws NetconfException {
43 StringBuilder sb = new StringBuilder();
44 sb.append(
45 "<components xmlns='http://openconfig.net/yang/platform'>"
Boyuan Yan8f9f6ad2019-06-12 16:54:42 -070046 + "<component nc:operation='merge'>"
hiroki337c5522019-01-20 20:05:51 -080047 + "<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 Campanella3a361452019-08-02 10:17:53 +020058 log.info("Optical Channel Frequency {}", sb.toString());
59 boolean ok = session.editConfig(DatastoreId.CANDIDATE, null, sb.toString());
hiroki337c5522019-01-20 20:05:51 -080060 if (!ok) {
61 throw new NetconfException("error writing channel frequency");
62 }
Andrea Campanella3a361452019-08-02 10:17:53 +020063 ok = session.commit();
64 if (!ok) {
65 throw new NetconfException("error committing channel frequency");
66 }
hiroki337c5522019-01-20 20:05:51 -080067 }
68
hiroki337c5522019-01-20 20:05:51 -080069}