blob: be27c890d2232d2d6b7822710dd13c4660c13e1f [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/*
2 * Copyright 2015-present Open Networking Laboratory
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.xran.impl;
18
19import com.fasterxml.jackson.databind.JsonNode;
20import org.apache.commons.lang.exception.ExceptionUtils;
21import org.onosproject.core.ApplicationId;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.config.Config;
24import org.onosproject.xran.codecs.api.ECGI;
25import org.onosproject.xran.codecs.api.EUTRANCellIdentifier;
26import org.onosproject.xran.codecs.api.PLMNIdentity;
27import org.openmuc.jasn1.util.HexConverter;
28import org.slf4j.Logger;
29import org.slf4j.LoggerFactory;
30
31import javax.xml.bind.DatatypeConverter;
32import java.io.ByteArrayInputStream;
33import java.io.IOException;
34import java.io.InputStream;
35import java.net.URI;
36import java.net.URISyntaxException;
37import java.util.Map;
38import java.util.concurrent.ConcurrentHashMap;
39
40import static org.onosproject.net.DeviceId.deviceId;
41
42public class XranConfig extends Config<ApplicationId> {
43
44 private static final String CELLS = "active_cells";
45
46 private static final String PLMN_ID = "plmn_id";
47 private static final String ECI_ID = "eci";
48
49 private static final String IP_ADDR = "ip_addr";
50
51 private static final String XRANC_PORT = "xranc_port";
52
53 private static final String XRANC_CELLCONFIG_INTERVAL = "xranc_cellconfigrequest_interval_seconds";
54
55 private static final String RX_SIGNAL_MEAS_REPORT_INTERVAL = "rx_signal_meas_report_interval_seconds";
56
57 private static final String L2_MEAS_REPORT_INTERVAL = "l2_meas_report_interval_ms";
58
59 private final Logger log = LoggerFactory.getLogger(getClass());
60
61 public Map<String, ECGI> activeCellSet() {
62 Map<String, ECGI> cells = new ConcurrentHashMap<>();
63
64 JsonNode cellsNode = object.get(CELLS);
65 if (cellsNode == null) {
66 log.warn("no cells have been provided!");
67 return cells;
68 }
69
70 cellsNode.forEach(cellNode -> {
71 String plmn_id = cellNode.get(PLMN_ID).asText();
72 String eci = cellNode.get(ECI_ID).asText();
73
74 String ipAddress = cellNode.get(IP_ADDR).asText();
75
76 ECGI ecgi = hexToECGI(plmn_id, eci);
77 cells.put(ipAddress, ecgi);
78 });
79
80 return cells;
81 }
82
83 public int getXrancPort() {
84 return object.get(XRANC_PORT).asInt();
85 }
86
87 public int getConfigRequestInterval() {
88 return object.get(XRANC_CELLCONFIG_INTERVAL).asInt();
89 }
90
91 public int getRxSignalInterval() {
92 return object.get(RX_SIGNAL_MEAS_REPORT_INTERVAL).asInt();
93 }
94
95 public int getL2MeasInterval() {
96 return object.get(L2_MEAS_REPORT_INTERVAL).asInt();
97 }
98
99
100 private ECGI hexToECGI(String plmn_id, String eci) {
101 byte[] bytes = HexConverter.fromShortHexString(plmn_id);
102 byte[] bytearray = DatatypeConverter.parseHexBinary(eci);
103
104 InputStream inputStream = new ByteArrayInputStream(bytearray);
105
106 PLMNIdentity plmnIdentity = new PLMNIdentity(bytes);
107 EUTRANCellIdentifier eutranCellIdentifier = new EUTRANCellIdentifier(bytearray, 28);
108
109 ECGI ecgi = new ECGI();
110 ecgi.setEUTRANcellIdentifier(eutranCellIdentifier);
111 ecgi.setPLMNIdentity(plmnIdentity);
112 try {
113 ecgi.decode(inputStream);
114 } catch (IOException e) {
115 e.printStackTrace();
116 }
117
118 return ecgi;
119 }
120}