*/
package org.opendaylight.netvirt.dhcpservice;
-import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.genius.mdsalutil.ActionInfo;
import org.opendaylight.genius.mdsalutil.FlowEntity;
import org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable;
import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.util.Datastore.Configuration;
+import org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction;
+import org.opendaylight.mdsal.binding.util.TypedWriteTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.netvirt.dhcpservice.api.DhcpMConstants;
import org.opendaylight.netvirt.elanmanager.api.IElanService;
-import org.opendaylight.netvirt.neutronvpn.interfaces.INeutronVpnManager;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.config.rev150710.DhcpserviceConfig;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG = LoggerFactory.getLogger(DhcpManager.class);
private final IMdsalApiManager mdsalUtil;
- private final INeutronVpnManager neutronVpnService;
private final DhcpserviceConfig config;
private final DataBroker broker;
private final DhcpExternalTunnelManager dhcpExternalTunnelManager;
private final IElanService elanService;
private final JobCoordinator jobCoordinator;
private DhcpPortCache dhcpPortCache;
+ private final ItmRpcService itmRpcService;
+ private final DhcpServiceCounters dhcpServiceCounters;
private volatile int dhcpOptLeaseTime = 0;
private volatile String dhcpOptDefDomainName;
@Inject
public DhcpManager(final IMdsalApiManager mdsalApiManager,
- final INeutronVpnManager neutronVpnManager,
final DhcpserviceConfig config, final DataBroker dataBroker,
final DhcpExternalTunnelManager dhcpExternalTunnelManager, final IInterfaceManager interfaceManager,
@Named("elanService") IElanService ielanService, final DhcpPortCache dhcpPortCache,
- final JobCoordinator jobCoordinator) {
+ final JobCoordinator jobCoordinator, final ItmRpcService itmRpcService,
+ DhcpServiceCounters dhcpServiceCounters) {
this.mdsalUtil = mdsalApiManager;
- this.neutronVpnService = neutronVpnManager;
this.config = config;
this.broker = dataBroker;
this.dhcpExternalTunnelManager = dhcpExternalTunnelManager;
this.elanService = ielanService;
this.dhcpPortCache = dhcpPortCache;
this.jobCoordinator = jobCoordinator;
+ this.itmRpcService = itmRpcService;
+ this.dhcpServiceCounters = dhcpServiceCounters;
configureLeaseDuration(DhcpMConstants.DEFAULT_LEASE_TIME);
}
LOG.trace("Netvirt DHCP Manager Init .... {}",config.isControllerDhcpEnabled());
if (config.isControllerDhcpEnabled()) {
dhcpInterfaceEventListener = new DhcpInterfaceEventListener(this, broker, dhcpExternalTunnelManager,
- interfaceManager, elanService, dhcpPortCache, jobCoordinator);
+ interfaceManager, elanService, dhcpPortCache, jobCoordinator, itmRpcService);
dhcpInterfaceConfigListener = new DhcpInterfaceConfigListener(broker, dhcpExternalTunnelManager, this,
jobCoordinator);
LOG.info("DHCP Service initialized");
this.dhcpOptLeaseTime = leaseTime;
}
+ @Nullable
public Subnet getNeutronSubnet(Port port) {
if (port != null) {
// DHCP Service is only interested in IPv4 IPs/Subnets
- return getNeutronSubnet(port.getFixedIps());
+ return getNeutronSubnet(new ArrayList<FixedIps>(port.nonnullFixedIps().values()));
}
return null;
}
+ @Nullable
public Subnet getNeutronSubnet(List<FixedIps> fixedIps) {
for (FixedIps fixedIp: fixedIps) {
if (fixedIp.getIpAddress().getIpv4Address() != null) {
- return neutronVpnService.getNeutronSubnet(fixedIp.getSubnetId());
+ return getNeutronSubnet(fixedIp.getSubnetId());
}
}
return null;
}
+ @Nullable
+ private Subnet getNeutronSubnet(Uuid subnetId) {
+ Subnet subnet = null;
+ InstanceIdentifier<Subnet> inst = InstanceIdentifier.create(Neutron.class).child(Subnets.class).child(Subnet
+ .class, new SubnetKey(subnetId));
+ Optional<Subnet> sn;
+ try {
+ sn = SingleTransactionDataBroker.syncReadOptional(broker, LogicalDatastoreType.CONFIGURATION,
+ inst);
+ } catch (ExecutionException | InterruptedException e) {
+ LOG.error("Exception while reading subnet DS for the subnetId {}", subnetId.getValue(), e);
+ return subnet;
+ }
+ if (sn.isPresent()) {
+ subnet = sn.get();
+ }
+ LOG.trace("Subnet {} = {}", subnetId, subnet);
+ return subnet;
+ }
+
+ @Nullable
public Port getNeutronPort(String name) {
+ Port prt = null;
+ InstanceIdentifier<Port> inst = InstanceIdentifier.create(Neutron.class).child(Ports.class).child(Port.class,
+ new PortKey(new Uuid(name)));
+ Optional<Port> port;
try {
- return neutronVpnService.getNeutronPort(name);
- } catch (IllegalArgumentException e) {
- return null;
+ port = SingleTransactionDataBroker.syncReadOptional(broker, LogicalDatastoreType.CONFIGURATION,
+ inst);
+ } catch (ExecutionException | InterruptedException e) {
+ LOG.error("Exception while reading port DS for the port {}", name, e);
+ return prt;
+ }
+ if (port.isPresent()) {
+ prt = port.get();
}
+ LOG.trace("Port {} = {}", name, prt);
+ return prt;
}
- public void installDhcpEntries(BigInteger dpnId, String vmMacAddress, WriteTransaction tx) {
+ public void installDhcpEntries(@Nullable Uint64 dpnId, @Nullable String vmMacAddress,
+ TypedReadWriteTransaction<Configuration> tx) throws ExecutionException, InterruptedException {
DhcpServiceUtils.setupDhcpFlowEntry(dpnId, NwConstants.DHCP_TABLE, vmMacAddress, NwConstants.ADD_FLOW,
- mdsalUtil, tx);
+ mdsalUtil, dhcpServiceCounters, tx);
}
- public void unInstallDhcpEntries(BigInteger dpId, String vmMacAddress, WriteTransaction tx) {
+ public void unInstallDhcpEntries(@Nullable Uint64 dpId, @Nullable String vmMacAddress,
+ TypedReadWriteTransaction<Configuration> tx) throws ExecutionException, InterruptedException {
DhcpServiceUtils.setupDhcpFlowEntry(dpId, NwConstants.DHCP_TABLE, vmMacAddress, NwConstants.DEL_FLOW,
- mdsalUtil, tx);
+ mdsalUtil, dhcpServiceCounters, tx);
}
- public void setupDefaultDhcpFlows(BigInteger dpId) {
- setupTableMissForDhcpTable(dpId);
+ public void setupDefaultDhcpFlows(TypedWriteTransaction<Configuration> tx, Uint64 dpId) {
+ setupTableMissForDhcpTable(tx, dpId);
if (config.isDhcpDynamicAllocationPoolEnabled()) {
- setupDhcpAllocationPoolFlow(dpId);
+ setupDhcpAllocationPoolFlow(tx, dpId);
}
}
- private void setupTableMissForDhcpTable(BigInteger dpId) {
+ private void setupTableMissForDhcpTable(TypedWriteTransaction<Configuration> tx, Uint64 dpId) {
List<MatchInfo> matches = new ArrayList<>();
List<InstructionInfo> instructions = new ArrayList<>();
List<ActionInfo> actionsInfos = new ArrayList<>();
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.DHCP_TABLE, "DHCPTableMissFlow",
0, "DHCP Table Miss Flow", 0, 0,
DhcpMConstants.COOKIE_DHCP_BASE, matches, instructions);
- DhcpServiceCounters.install_dhcp_table_miss_flow.inc();
- mdsalUtil.installFlow(flowEntity);
- setupTableMissForHandlingExternalTunnel(dpId);
+ dhcpServiceCounters.installDhcpTableMissFlow();
+ mdsalUtil.addFlow(tx, flowEntity);
+ setupTableMissForHandlingExternalTunnel(tx, dpId);
}
- private void setupDhcpAllocationPoolFlow(BigInteger dpId) {
+ private void setupDhcpAllocationPoolFlow(TypedWriteTransaction<Configuration> tx, Uint64 dpId) {
List<MatchInfo> matches = DhcpServiceUtils.getDhcpMatch();
List<InstructionInfo> instructions = new ArrayList<>();
List<ActionInfo> actionsInfos = new ArrayList<>();
"DhcpAllocationPoolFlow", DhcpMConstants.DEFAULT_DHCP_ALLOCATION_POOL_FLOW_PRIORITY,
"Dhcp Allocation Pool Flow", 0, 0, DhcpMConstants.COOKIE_DHCP_BASE, matches, instructions);
LOG.trace("Installing DHCP Allocation Pool Flow DpId {}", dpId);
- DhcpServiceCounters.install_dhcp_flow.inc();
- mdsalUtil.installFlow(flowEntity);
+ dhcpServiceCounters.installDhcpFlow();
+ mdsalUtil.addFlow(tx, flowEntity);
}
- private void setupTableMissForHandlingExternalTunnel(BigInteger dpId) {
+ private void setupTableMissForHandlingExternalTunnel(TypedWriteTransaction<Configuration> tx, Uint64 dpId) {
List<MatchInfo> matches = new ArrayList<>();
List<InstructionInfo> instructions = new ArrayList<>();
instructions.add(new InstructionGotoTable(NwConstants.EXTERNAL_TUNNEL_TABLE));
"DHCPTableMissFlowForExternalTunnel",
0, "DHCP Table Miss Flow For External Tunnel", 0, 0,
DhcpMConstants.COOKIE_DHCP_BASE, matches, instructions);
- DhcpServiceCounters.install_dhcp_table_miss_flow_for_external_table.inc();
- mdsalUtil.installFlow(flowEntity);
+ dhcpServiceCounters.installDhcpTableMissFlowForExternalTable();
+ mdsalUtil.addFlow(tx, flowEntity);
}
}