blob: 7dafaf4260e9f13c7f7bfda7f5b9704419a4df00 [file] [log] [blame]
Amit Ghosh47243cb2017-07-26 05:08:53 +01001/*
Brian O'Connor10570622017-08-03 22:45:53 -07002 * Copyright 2017-present Open Networking Foundation
Amit Ghosh47243cb2017-07-26 05:08: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 */
Matteo Scandolo57af5d12019-04-29 17:11:41 -070016package org.opencord.dhcpl2relay.impl;
Amit Ghosh47243cb2017-07-26 05:08:53 +010017
Amit Ghosh8951f042017-08-10 13:48:10 +010018import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.node.ArrayNode;
20
21import com.google.common.collect.ImmutableSet;
22
Amit Ghosh47243cb2017-07-26 05:08:53 +010023import org.onosproject.core.ApplicationId;
24import org.onosproject.net.ConnectPoint;
25import org.onosproject.net.config.Config;
26
Amit Ghosh8951f042017-08-10 13:48:10 +010027import java.util.HashSet;
28import java.util.Set;
29
Amit Ghosh47243cb2017-07-26 05:08:53 +010030
31/**
32 * DHCP Relay Config class.
33 */
34public class DhcpL2RelayConfig extends Config<ApplicationId> {
35
Amit Ghosh8951f042017-08-10 13:48:10 +010036 private static final String DHCP_CONNECT_POINTS = "dhcpServerConnectPoints";
Amit Ghosh83c8c892017-11-09 11:08:27 +000037 private static final String MODIFY_SRC_DST_MAC = "modifyUlPacketsSrcDstMacAddresses";
38 private static final String USE_OLT_ULPORT_FOR_PKT_INOUT = "useOltUplinkForServerPktInOut";
39
Marcos Aurelio Carreroeaf02b82019-11-25 13:34:25 -030040 protected static final Boolean DEFAULT_MODIFY_SRC_DST_MAC = false;
41 protected static final Boolean DEFAULT_USE_OLT_ULPORT_FOR_PKT_INOUT = false;
Amit Ghosh47243cb2017-07-26 05:08:53 +010042
43 @Override
44 public boolean isValid() {
45
Amit Ghosh83c8c892017-11-09 11:08:27 +000046 return hasOnlyFields(DHCP_CONNECT_POINTS, MODIFY_SRC_DST_MAC,
47 USE_OLT_ULPORT_FOR_PKT_INOUT);
48 }
49
50 /**
51 * Returns whether the app would use the uplink port of OLT for sending/receving
52 * messages to/from the server.
53 *
54 * @return true if OLT uplink port is to be used, false otherwise
55 */
56 public boolean getUseOltUplinkForServerPktInOut() {
57 if (object == null) {
58 return DEFAULT_USE_OLT_ULPORT_FOR_PKT_INOUT;
59 }
60 if (!object.has(USE_OLT_ULPORT_FOR_PKT_INOUT)) {
61 return DEFAULT_USE_OLT_ULPORT_FOR_PKT_INOUT;
62 }
63
64 return object.path(USE_OLT_ULPORT_FOR_PKT_INOUT).asBoolean();
65 }
66
67 /**
68 * Returns whether the app would modify MAC address of uplink packets.
69 *
70 * @return whether app would modify src and dst MAC addresses or not of packets
71 * sent to the DHCP server
72 */
73 public boolean getModifySrcDstMacAddresses() {
74 if (object == null) {
75 return DEFAULT_MODIFY_SRC_DST_MAC;
76 }
77 if (!object.has(MODIFY_SRC_DST_MAC)) {
78 return DEFAULT_MODIFY_SRC_DST_MAC;
79 }
80
81 return object.path(MODIFY_SRC_DST_MAC).asBoolean();
Amit Ghosh47243cb2017-07-26 05:08:53 +010082 }
83
84 /**
Amit Ghosh8951f042017-08-10 13:48:10 +010085 * Returns the dhcp server connect points.
Amit Ghosh47243cb2017-07-26 05:08:53 +010086 *
Amit Ghosh8951f042017-08-10 13:48:10 +010087 * @return dhcp server connect points
Amit Ghosh47243cb2017-07-26 05:08:53 +010088 */
Amit Ghosh8951f042017-08-10 13:48:10 +010089 public Set<ConnectPoint> getDhcpServerConnectPoint() {
90 if (object == null) {
91 return new HashSet<ConnectPoint>();
92 }
93
94 if (!object.has(DHCP_CONNECT_POINTS)) {
95 return ImmutableSet.of();
96 }
97
98 ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder();
99 ArrayNode arrayNode = (ArrayNode) object.path(DHCP_CONNECT_POINTS);
100 for (JsonNode jsonNode : arrayNode) {
101 String portName = jsonNode.asText(null);
102 if (portName == null) {
103 return null;
104 }
105 try {
106 builder.add(ConnectPoint.deviceConnectPoint(portName));
107 } catch (IllegalArgumentException e) {
108 return null;
109 }
110 }
111 return builder.build();
Amit Ghosh47243cb2017-07-26 05:08:53 +0100112 }
113}