blob: 13fcc1f8c3c8ef6b13a9388b388650305930ce79 [file] [log] [blame]
Gamze Abaka1e5ccf52018-07-02 11:59:03 +00001/*
2 * Copyright 2017-present 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 */
16package org.opencord.sadis.impl;
17
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000018import com.fasterxml.jackson.core.JsonParser;
19import com.fasterxml.jackson.core.ObjectCodec;
20import com.fasterxml.jackson.databind.DeserializationContext;
21import com.fasterxml.jackson.databind.JsonDeserializer;
22import com.fasterxml.jackson.databind.JsonNode;
23import com.fasterxml.jackson.databind.ObjectMapper;
24import com.fasterxml.jackson.databind.module.SimpleModule;
Andrea Campanellacd431d92022-02-08 10:10:17 +010025import org.onlab.packet.Ip4Address;
26import org.onlab.packet.VlanId;
27import org.opencord.sadis.BaseConfig;
28import org.opencord.sadis.SubscriberAndDeviceInformation;
29import org.opencord.sadis.UniTagInformation;
30import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32
33import java.io.IOException;
34import java.util.ArrayList;
35import java.util.List;
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000036
37/**
38 * Configuration options for the Subscriber And Device Information Service.
39 *
40 * <pre>
41 * "sadis" : {
42 * "integration" : {
43 * "url" : "http://{hostname}{:port}",
44 * "cache" : {
45 * "maxsize" : number of entries,
46 * "entryttl" : duration, i.e. 10s or 1m
47 * }
48 * },
49 * "entries" : [
50 * {
51 * "id" : "uniqueid",
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000052 * "nasportid" : string,
53 * "port" : int,
54 * "slot" : int,
55 * "hardwareidentifier" : string,
56 * "ipAddress" : string,
57 * "nasId" : string,
58 * "circuitId" : string,
Matteo Scandolo198aef92020-01-08 00:43:17 +000059 * "remoteId" : string,
amit.ghosh3b225bb2022-02-17 18:41:00 +010060 * "nniDhcpTrapVid" : string,
Matteo Scandolo198aef92020-01-08 00:43:17 +000061 * "uniTagList": [
62 * {
yasin sapli2c93ddb2021-06-11 17:46:26 +030063 * "uniTagMatch" : int,
64 * "ponCTag" : string,
65 * "ponSTag" : string,
66 * "usPonCTagPriority" : int,
67 * "dsPonCTagPriority" : int,
68 * "usPonSTagPriority" : int,
69 * "dsPonSTagPriority" : int,
70 * "technologyProfileId" : int,
71 * "upstreamBandwidthProfile" : string,
72 * "downstreamBandwidthProfile" : string,
73 * "upstreamOltBandwidthProfile" : string,
74 * "downstreamOltBandwidthProfile" : string,
75 * "enableMacLearning" : string,
Andrea Campanellacd431d92022-02-08 10:10:17 +010076 * "configuredMacAddress" : string,
yasin sapli2c93ddb2021-06-11 17:46:26 +030077 * "isDhcpRequired" : string,
78 * "isIgmpRequired" : string,
yasin sapli9e3ebed2021-07-09 14:06:35 +000079 * "isPppoeRequired" : string,
yasin sapli2c93ddb2021-06-11 17:46:26 +030080 * "serviceName" : string
Matteo Scandolo198aef92020-01-08 00:43:17 +000081 * }
yasin sapli2c93ddb2021-06-11 17:46:26 +030082 * ]
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000083 * }, ...
84 * ]
85 * }
86 * </pre>
87 */
88public class SubscriberAndDeviceInformationConfig extends BaseConfig<SubscriberAndDeviceInformation> {
89
90 private final Logger log = LoggerFactory.getLogger(this.getClass());
Matteo Scandolo198aef92020-01-08 00:43:17 +000091 private static final int NO_PCP = -1;
Andrea Campanella30041b92022-01-28 16:09:08 +010092 private static final int NO_TP = -1;
Matteo Scandolo198aef92020-01-08 00:43:17 +000093 private static final String NO_SN = "";
Andrea Campanellacd431d92022-02-08 10:10:17 +010094 private static final String EMPTY_MAC = "";
Matteo Scandolo198aef92020-01-08 00:43:17 +000095 private static final String UNI_TAG_MATCH = "uniTagMatch";
96 private static final String PON_C_TAG = "ponCTag";
97 private static final String PON_S_TAG = "ponSTag";
98 private static final String US_C_TAG_PCP = "usPonCTagPriority";
99 private static final String US_S_TAG_PCP = "usPonSTagPriority";
100 private static final String DS_C_TAG_PCP = "dsPonCTagPriority";
101 private static final String DS_S_TAG_PCP = "dsPonSTagPriority";
102 private static final String MAC_LEARNING = "enableMacLearning";
103 private static final String TP_ID = "technologyProfileId";
104 private static final String US_BW = "upstreamBandwidthProfile";
105 private static final String DS_BW = "downstreamBandwidthProfile";
yasin sapli2c93ddb2021-06-11 17:46:26 +0300106 private static final String US_OLT_BW = "upstreamOltBandwidthProfile";
107 private static final String DS_OLT_BW = "downstreamOltBandwidthProfile";
Matteo Scandolo198aef92020-01-08 00:43:17 +0000108 private static final String SERVICE_NAME = "serviceName";
109 private static final String IS_DHCP_REQ = "isDhcpRequired";
110 private static final String IS_IGMP_REQ = "isIgmpRequired";
yasin sapli9e3ebed2021-07-09 14:06:35 +0000111 private static final String IS_PPPOE_REQ = "isPppoeRequired";
Matteo Scandolo198aef92020-01-08 00:43:17 +0000112 private static final String MAC_ADDRESS = "configuredMacAddress";
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000113
114 public List<SubscriberAndDeviceInformation> getEntries() {
115 List<SubscriberAndDeviceInformation> result = new ArrayList<>();
116 ObjectMapper mapper = new ObjectMapper();
117 SimpleModule module = new SimpleModule();
118 module.addDeserializer(VlanId.class, new VlanIdDeserializer());
119 module.addDeserializer(Ip4Address.class, new Ip4AddressDeserializer());
Matteo Scandolo198aef92020-01-08 00:43:17 +0000120 module.addDeserializer(UniTagInformation.class, new UniTagDeserializer());
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000121 mapper.registerModule(module);
122 final JsonNode entries = this.object.path(ENTRIES);
123 entries.forEach(entry -> {
124 try {
125 result.add(mapper.readValue(entry.toString(), SubscriberAndDeviceInformation.class));
126 } catch (IOException e) {
127 log.warn("Unable to parse configuration entry, '{}', error: {}", entry, e.getMessage());
128 }
129 });
130
131 return result;
132 }
133
134 public class VlanIdDeserializer extends JsonDeserializer<VlanId> {
135 @Override
136 public VlanId deserialize(JsonParser jp, DeserializationContext ctxt)
137 throws IOException {
138 ObjectCodec oc = jp.getCodec();
139 JsonNode node = oc.readTree(jp);
140 return VlanId.vlanId((short) node.asInt());
141 }
142 }
143
144 public class Ip4AddressDeserializer extends JsonDeserializer<Ip4Address> {
145 @Override
146 public Ip4Address deserialize(JsonParser jp, DeserializationContext ctxt)
147 throws IOException {
148 ObjectCodec oc = jp.getCodec();
149 JsonNode node = oc.readTree(jp);
150 return Ip4Address.valueOf(node.asText());
151 }
152 }
Matteo Scandolo198aef92020-01-08 00:43:17 +0000153
154 public class UniTagDeserializer extends JsonDeserializer<UniTagInformation> {
155 @Override
156 public UniTagInformation deserialize(JsonParser jp, DeserializationContext ctxt)
157 throws IOException {
158 ObjectCodec oc = jp.getCodec();
159 JsonNode node = oc.readTree(jp);
160 return getUniTagInformation(node);
161 }
162 }
163
164 public UniTagInformation getUniTagInformation(JsonNode node) {
yasin sapli2c93ddb2021-06-11 17:46:26 +0300165 String usBw = node.get(US_BW) == null ? null : node.get(US_BW).asText();
166 String dsBw = node.get(DS_BW) == null ? null : node.get(DS_BW).asText();
Matteo Scandolo198aef92020-01-08 00:43:17 +0000167 return new UniTagInformation.Builder()
168 .setUniTagMatch(VlanId.vlanId(node.get(UNI_TAG_MATCH) == null ? VlanId.NO_VID
169 : (short) node.get(UNI_TAG_MATCH).asInt()))
Andrea Campanella30041b92022-01-28 16:09:08 +0100170 .setPonCTag(node.get(PON_C_TAG) == null ? VlanId.vlanId(VlanId.NO_VID) :
171 VlanId.vlanId(node.get(PON_C_TAG).shortValue()))
172 .setPonSTag(node.get(PON_S_TAG) == null ? VlanId.vlanId(VlanId.NO_VID) :
173 VlanId.vlanId(node.get(PON_S_TAG).shortValue()))
Matteo Scandolo198aef92020-01-08 00:43:17 +0000174 .setUsPonCTagPriority(node.get(US_C_TAG_PCP) == null ? NO_PCP :
175 node.get(US_C_TAG_PCP).asInt())
176 .setUsPonSTagPriority(node.get(US_S_TAG_PCP) == null ? NO_PCP :
177 node.get(US_S_TAG_PCP).asInt())
178 .setDsPonCTagPriority(node.get(DS_C_TAG_PCP) == null ? NO_PCP :
179 node.get(DS_C_TAG_PCP).asInt())
180 .setDsPonSTagPriority(node.get(DS_S_TAG_PCP) == null ? NO_PCP :
181 node.get(DS_S_TAG_PCP).asInt())
Andrea Campanella30041b92022-01-28 16:09:08 +0100182 .setEnableMacLearning(node.get(MAC_LEARNING) != null && node.get(MAC_LEARNING).asBoolean())
183 .setTechnologyProfileId(node.get(TP_ID) == null ? NO_TP : node.get(TP_ID).asInt())
yasin sapli2c93ddb2021-06-11 17:46:26 +0300184 .setUpstreamBandwidthProfile(usBw)
185 .setDownstreamBandwidthProfile(dsBw)
186 .setUpstreamOltBandwidthProfile(node.get(US_OLT_BW) == null ? usBw
187 : node.get(US_OLT_BW).asText())
188 .setDownstreamOltBandwidthProfile(node.get(DS_OLT_BW) == null ? dsBw
189 : node.get(DS_OLT_BW).asText())
Matteo Scandolo198aef92020-01-08 00:43:17 +0000190 .setServiceName(node.get(SERVICE_NAME) == null ? NO_SN :
191 node.get(SERVICE_NAME).asText())
Andrea Campanella30041b92022-01-28 16:09:08 +0100192 .setIsDhcpRequired(node.get(IS_DHCP_REQ) != null && node.get(IS_DHCP_REQ).asBoolean())
193 .setIsIgmpRequired(node.get(IS_IGMP_REQ) != null && node.get(IS_IGMP_REQ).asBoolean())
yasin sapli9e3ebed2021-07-09 14:06:35 +0000194 .setIsPppoeRequired(node.get(IS_PPPOE_REQ) != null && node.get(IS_PPPOE_REQ).asBoolean())
Andrea Campanellacd431d92022-02-08 10:10:17 +0100195 .setConfiguredMacAddress(node.get(MAC_ADDRESS) == null ? EMPTY_MAC :
Matteo Scandolo198aef92020-01-08 00:43:17 +0000196 node.get(MAC_ADDRESS).asText())
197 .build();
198 }
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000199}