blob: 124337e31ea95f530dcb64653cd2d559b9554f2c [file] [log] [blame]
Jan Kundrát981fe472019-10-15 22:44:19 +02001/*
2 * Copyright 2019-2020 Jan Kundrát, CESNET, <jan.kundrat@cesnet.cz> and Open Networking Foundation
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
17package org.onosproject.drivers.czechlight;
18
19import org.apache.commons.configuration.HierarchicalConfiguration;
20import org.onosproject.net.OchSignal;
21
22import java.util.Map;
23import java.util.stream.Collectors;
24
25/** Media Channel definition specifies a frequency range, i.e., a channel in a flexgrid DWDM system as retrieved from
26 * the ROADM device. We cannot use something like an OchSignal because this represents raw data on the device.
27 */
28class MediaChannelDefinition {
29 public int lowMHz;
30 public int highMHz;
31
32 public MediaChannelDefinition(final int lowMHz, final int highMHz) {
33 this.lowMHz = lowMHz;
34 this.highMHz = highMHz;
35 }
36
37 public String toString() {
38 return "Channel{" + String.valueOf(lowMHz / 1_000_000.0) + " - " + String.valueOf(highMHz / 1_000_000.0) + "}";
39 }
40
41 public static Map<String, MediaChannelDefinition> parseChannelDefinitions(final HierarchicalConfiguration xml) {
42 return xml.configurationsAt("data.channel-plan.channel").stream()
43 .collect(Collectors.toMap(x -> x.getString("name"),
44 x -> new MediaChannelDefinition(x.getInt("lower-frequency"),
45 x.getInt("upper-frequency"))));
46 }
47
48 public static boolean mcMatches(final Map.Entry<String, MediaChannelDefinition> entry, final OchSignal och) {
49 return entry.getValue().lowMHz == och.centralFrequency().asMHz() - och.slotWidth().asMHz() / 2
50 && entry.getValue().highMHz == och.centralFrequency().asMHz() + och.slotWidth().asMHz() / 2;
51 }
52
53};
54