blob: 454957aff465e93c3e0737e4b57f6289b88ce926 [file] [log] [blame]
qphamvan9aedb562019-02-19 14:38:53 +01001/*
Sudeep Desai6f136d42019-11-25 14:42:43 +05302 * Copyright 2019-present Open Networking Foundation
qphamvan9aedb562019-02-19 14:38:53 +01003 *
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
18package org.onosproject.drivers.odtn;
19
qphamvan9aedb562019-02-19 14:38:53 +010020import org.onlab.util.Frequency;
Sudeep Desai6f136d42019-11-25 14:42:43 +053021import org.onosproject.drivers.odtn.openconfig.AbstractTerminalDeviceFlowRuleProgrammable;
qphamvan9aedb562019-02-19 14:38:53 +010022import org.onosproject.netconf.DatastoreId;
qphamvan9aedb562019-02-19 14:38:53 +010023import org.onosproject.netconf.NetconfException;
24import org.onosproject.netconf.NetconfSession;
25import org.slf4j.Logger;
26import org.slf4j.LoggerFactory;
27
qphamvan9aedb562019-02-19 14:38:53 +010028/**
29 * Implementation of FlowRuleProgrammable interface for
30 * OpenConfig terminal devices.
31 */
32public class NokiaFlowRuleProgrammable
Sudeep Desai6f136d42019-11-25 14:42:43 +053033 extends AbstractTerminalDeviceFlowRuleProgrammable {
qphamvan9aedb562019-02-19 14:38:53 +010034
35 private static final Logger log =
36 LoggerFactory.getLogger(NokiaFlowRuleProgrammable.class);
37
Sudeep Desai6f136d42019-11-25 14:42:43 +053038 public void setOpticalChannelFrequency(NetconfSession session,
qphamvan9aedb562019-02-19 14:38:53 +010039 String optChannel, Frequency freq)
40 throws NetconfException {
Quan PHAM VAN84ac1812019-02-28 16:22:45 +010041 String[] textStr = optChannel.split("-");
qphamvan9aedb562019-02-19 14:38:53 +010042 StringBuilder sb = new StringBuilder();
43 sb.append(
44 "<components xmlns='http://openconfig.net/yang/platform'>"
45 + "<component operation='merge'>"
Quan PHAM VAN84ac1812019-02-28 16:22:45 +010046 + "<name>" + "OCH-" + textStr[1] + "-" + textStr[2] + "-" + textStr[3] + "</name>"
qphamvan9aedb562019-02-19 14:38:53 +010047 + "<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
qphamvan9aedb562019-02-19 14:38:53 +010065}