OSGi property annotations for dhcp relay app

Change-Id: I5859f28d087e907548923e9526a8c1c0624f3cb0
This commit is contained in:
Ray Milkey 2018-10-31 10:18:41 -07:00
parent 7cc3e7d8fb
commit 687c00c7db
5 changed files with 90 additions and 30 deletions

View File

@ -115,20 +115,25 @@ import static org.onlab.packet.DHCP.DHCPOptionCode.OptionCode_MessageType;
import static org.onlab.packet.MacAddress.valueOf;
import static org.onlab.packet.dhcp.DhcpRelayAgentOption.RelayAgentInfoOptions.CIRCUIT_ID;
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.dhcprelay.OsgiPropertyConstants.LEARN_ROUTE_FROM_LEASE_QUERY;
import static org.onosproject.dhcprelay.OsgiPropertyConstants.LEARN_ROUTE_FROM_LEASE_QUERY_DEFAULT;
import static org.onosproject.net.flowobjective.Objective.Operation.ADD;
import static org.onosproject.net.flowobjective.Objective.Operation.REMOVE;
@Component(service = { DhcpHandler.class, HostProvider.class })
//@Property(name = "version", value = "4")
@Component(
service = { DhcpHandler.class, HostProvider.class },
property = {
"version:Integer = 4",
LEARN_ROUTE_FROM_LEASE_QUERY + ":Boolean=" + LEARN_ROUTE_FROM_LEASE_QUERY_DEFAULT
}
)
public class Dhcp4HandlerImpl implements DhcpHandler, HostProvider {
public static final String DHCP_V4_RELAY_APP = "org.onosproject.Dhcp4HandlerImpl";
public static final ProviderId PROVIDER_ID = new ProviderId("dhcp4", DHCP_V4_RELAY_APP);
private static final String BROADCAST_IP = "255.255.255.255";
private static final int IGNORE_CONTROL_PRIORITY = PacketPriority.CONTROL.priorityValue() + 1000;
private static final String LQ_ROUTE_PROPERTY_NAME = "learnRouteFromLeasequery";
private static final TrafficSelector CLIENT_SERVER_SELECTOR = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(IPv4.PROTOCOL_UDP)
@ -187,9 +192,8 @@ public class Dhcp4HandlerImpl implements DhcpHandler, HostProvider {
private List<DhcpServerInfo> defaultServerInfoList = new CopyOnWriteArrayList<>();
private List<DhcpServerInfo> indirectServerInfoList = new CopyOnWriteArrayList<>();
//@Property(name = Dhcp4HandlerImpl.LQ_ROUTE_PROPERTY_NAME, boolValue = false,
// label = "Enable learning routing information from LQ")
private Boolean learnRouteFromLeasequery = Boolean.TRUE;
/** Enable learning routing information from LQ. */
private Boolean learnRouteFromLeasequery = LEARN_ROUTE_FROM_LEASE_QUERY_DEFAULT;
private Executor hostEventExecutor = newSingleThreadExecutor(
groupedThreads("dhcp4-event-host", "%d", log));
@ -220,7 +224,7 @@ public class Dhcp4HandlerImpl implements DhcpHandler, HostProvider {
protected void modified(ComponentContext context) {
Dictionary<?, ?> properties = context.getProperties();
Boolean flag;
flag = Tools.isPropertyEnabled(properties, Dhcp4HandlerImpl.LQ_ROUTE_PROPERTY_NAME);
flag = Tools.isPropertyEnabled(properties, LEARN_ROUTE_FROM_LEASE_QUERY);
if (flag != null) {
learnRouteFromLeasequery = flag;
log.info("Learning routes from DHCP leasequery is {}",

View File

@ -120,18 +120,25 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.dhcprelay.OsgiPropertyConstants.LEARN_ROUTE_FROM_LEASE_QUERY;
import static org.onosproject.dhcprelay.OsgiPropertyConstants.LEARN_ROUTE_FROM_LEASE_QUERY_DEFAULT;
import static org.onosproject.net.flowobjective.Objective.Operation.ADD;
import static org.onosproject.net.flowobjective.Objective.Operation.REMOVE;
import java.util.concurrent.Semaphore;
@Component(service = { DhcpHandler.class, HostProvider.class })
//@Property(name = "version", value = "6")
@Component(
service = { DhcpHandler.class, HostProvider.class },
property = {
"version:Integer=6",
LEARN_ROUTE_FROM_LEASE_QUERY + ":Boolean=" + LEARN_ROUTE_FROM_LEASE_QUERY_DEFAULT
}
)
public class Dhcp6HandlerImpl implements DhcpHandler, HostProvider {
public static final String DHCP_V6_RELAY_APP = "org.onosproject.Dhcp6HandlerImpl";
public static final ProviderId PROVIDER_ID = new ProviderId("dhcp6", DHCP_V6_RELAY_APP);
private static final int IGNORE_CONTROL_PRIORITY = PacketPriority.CONTROL.priorityValue() + 1000;
private String gCount = "global";
private static final String LQ_ROUTE_PROPERTY_NAME = "learnRouteFromLeasequery";
private static final TrafficSelector CLIENT_SERVER_SELECTOR = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV6)
.matchIPProtocol(IPv6.PROTOCOL_UDP)
@ -197,9 +204,8 @@ public class Dhcp6HandlerImpl implements DhcpHandler, HostProvider {
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected ComponentConfigService cfgService;
//@Property(name = Dhcp6HandlerImpl.LQ_ROUTE_PROPERTY_NAME, boolValue = false,
// label = "Enable learning routing information from LQ")
private Boolean learnRouteFromLeasequery = Boolean.TRUE;
/** Enable learning routing information from LQ. */
private Boolean learnRouteFromLeasequery = LEARN_ROUTE_FROM_LEASE_QUERY_DEFAULT;
protected HostProviderService providerService;
protected ApplicationId appId;
@ -267,7 +273,7 @@ public class Dhcp6HandlerImpl implements DhcpHandler, HostProvider {
protected void modified(ComponentContext context) {
Dictionary<?, ?> properties = context.getProperties();
Boolean flag;
flag = Tools.isPropertyEnabled(properties, Dhcp6HandlerImpl.LQ_ROUTE_PROPERTY_NAME);
flag = Tools.isPropertyEnabled(properties, LEARN_ROUTE_FROM_LEASE_QUERY);
if (flag != null) {
learnRouteFromLeasequery = flag;
log.info("Learning routes from DHCP leasequery is {}",

View File

@ -96,12 +96,26 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.dhcprelay.OsgiPropertyConstants.ARP_ENABLED;
import static org.onosproject.dhcprelay.OsgiPropertyConstants.ARP_ENABLED_DEFAULT;
import static org.onosproject.dhcprelay.OsgiPropertyConstants.DHCP_FPM_ENABLED;
import static org.onosproject.dhcprelay.OsgiPropertyConstants.DHCP_FPM_ENABLED_DEFAULT;
import static org.onosproject.dhcprelay.OsgiPropertyConstants.DHCP_POLL_INTERVAL;
import static org.onosproject.dhcprelay.OsgiPropertyConstants.DHCP_POLL_INTERVAL_DEFAULT;
import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
/**
* DHCP Relay Agent Application Component.
*/
@Component(immediate = true, service = DhcpRelayService.class)
@Component(
immediate = true,
service = DhcpRelayService.class,
property = {
ARP_ENABLED + ":Boolean=" + ARP_ENABLED_DEFAULT,
DHCP_POLL_INTERVAL + ":Integer=" + DHCP_POLL_INTERVAL_DEFAULT,
DHCP_FPM_ENABLED + ":Boolean=" + DHCP_FPM_ENABLED_DEFAULT
}
)
public class DhcpRelayManager implements DhcpRelayService {
public static final String DHCP_RELAY_APP = "org.onosproject.dhcprelay";
public static final String ROUTE_STORE_IMPL =
@ -188,17 +202,14 @@ public class DhcpRelayManager implements DhcpRelayService {
target = "(version=6)")
protected DhcpHandler v6Handler;
//@Property(name = "arpEnabled", boolValue = true,
// label = "Enable Address resolution protocol")
protected boolean arpEnabled = true;
/** Enable Address resolution protocol. */
protected boolean arpEnabled = ARP_ENABLED_DEFAULT;
//@Property(name = "dhcpPollInterval", intValue = 24 * 3600,
// label = "dhcp relay poll interval")
protected int dhcpPollInterval = 24 * 3600;
/** dhcp relay poll interval. */
protected int dhcpPollInterval = DHCP_POLL_INTERVAL_DEFAULT;
//@Property(name = "dhcpFpmEnabled", boolValue = false,
// label = "Enable DhcpRelay Fpm")
protected boolean dhcpFpmEnabled = false;
/** Enable DhcpRelay Fpm. */
protected boolean dhcpFpmEnabled = DHCP_FPM_ENABLED_DEFAULT;
private ScheduledExecutorService timerExecutor;
@ -269,7 +280,7 @@ public class DhcpRelayManager implements DhcpRelayService {
Dictionary<?, ?> properties = context.getProperties();
Boolean flag;
flag = Tools.isPropertyEnabled(properties, "arpEnabled");
flag = Tools.isPropertyEnabled(properties, ARP_ENABLED);
if (flag != null) {
arpEnabled = flag;
log.info("Address resolution protocol is {}",
@ -282,7 +293,7 @@ public class DhcpRelayManager implements DhcpRelayService {
cancelArpPackets();
}
int intervalVal = Tools.getIntegerProperty(properties, "dhcpPollInterval");
int intervalVal = Tools.getIntegerProperty(properties, DHCP_POLL_INTERVAL);
log.info("DhcpRelay poll interval new {} old {}", intervalVal, dhcpPollInterval);
if (intervalVal != dhcpPollInterval) {
timerExecutor.shutdown();
@ -297,7 +308,7 @@ public class DhcpRelayManager implements DhcpRelayService {
v6Handler.setDhcp6PollInterval(dhcpPollInterval);
}
flag = Tools.isPropertyEnabled(properties, "dhcpFpmEnabled");
flag = Tools.isPropertyEnabled(properties, DHCP_FPM_ENABLED);
if (flag != null) {
boolean oldValue = dhcpFpmEnabled;
dhcpFpmEnabled = flag;

View File

@ -0,0 +1,34 @@
/*
* Copyright 2018-present Open Networking Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.dhcprelay;
public final class OsgiPropertyConstants {
private OsgiPropertyConstants() {
}
static final String ARP_ENABLED = "arpEnabled";
static final boolean ARP_ENABLED_DEFAULT = true;
static final String DHCP_POLL_INTERVAL = "dhcpPollInterval";
static final int DHCP_POLL_INTERVAL_DEFAULT = 86400;
static final String DHCP_FPM_ENABLED = "dhcpFpmEnabled";
static final boolean DHCP_FPM_ENABLED_DEFAULT = false;
static final String LEARN_ROUTE_FROM_LEASE_QUERY = "learnRouteFromLeasequery";
static final boolean LEARN_ROUTE_FROM_LEASE_QUERY_DEFAULT = false;
}

View File

@ -43,8 +43,13 @@ import static org.slf4j.LoggerFactory.getLogger;
/**
* Persistent Fpm Prefix Store with Listener.
*/
@Component(immediate = true, service = DhcpFpmPrefixStore.class)
//@Property(name = "fpm_type", value = "DHCP")
@Component(
immediate = true,
service = DhcpFpmPrefixStore.class,
property = {
"fpm_type=DHCP"
}
)
public class DistributedFpmPrefixStore implements DhcpFpmPrefixStore {
private static final KryoNamespace APP_KRYO = KryoNamespace.newBuilder()