/*
- * Copyright IBM Corporation, 2013. All rights reserved.
+ * Copyright (c) 2013, 2015 IBM Corporation and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
import org.opendaylight.neutron.spi.INeutronRouterCRUD;
+import org.opendaylight.neutron.spi.Neutron_IPs;
import org.opendaylight.neutron.spi.NeutronRouter;
import org.opendaylight.neutron.spi.NeutronRouter_Interface;
import org.opendaylight.neutron.spi.NeutronRouter_NetworkReference;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev141002.routers.attributes.Routers;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev141002.routers.attributes.routers.Router;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev141002.routers.attributes.routers.RouterBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev141002.routers.attributes.routers.router.ExternalGatewayInfo;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev141002.routers.attributes.routers.router.ExternalGatewayInfoBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev141002.routers.attributes.routers.router.Interfaces;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev141002.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150325.Neutron;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.RouterBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.ExternalGatewayInfo;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.ExternalGatewayInfoBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIpsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.Interfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class NeutronRouterInterface extends AbstractNeutronInterface<Router, NeutronRouter> implements INeutronRouterCRUD {
+public class NeutronRouterInterface extends AbstractNeutronInterface<Router, Routers, NeutronRouter> implements INeutronRouterCRUD {
private static final Logger LOGGER = LoggerFactory.getLogger(NeutronRouterInterface.class);
- private ConcurrentMap<String, NeutronRouter> routerDB = new ConcurrentHashMap<String, NeutronRouter>();
// methods needed for creating caches
@Override
public boolean routerExists(String uuid) {
- return routerDB.containsKey(uuid);
+ return exists(uuid);
}
@Override
public NeutronRouter getRouter(String uuid) {
- if (!routerExists(uuid)) {
- return null;
- }
- return routerDB.get(uuid);
+ return get(uuid);
+ }
+
+ @Override
+ protected List<Router> getDataObjectList(Routers routers) {
+ return routers.getRouter();
}
@Override
public List<NeutronRouter> getAllRouters() {
- Set<NeutronRouter> allRouters = new HashSet<NeutronRouter>();
- for (Entry<String, NeutronRouter> entry : routerDB.entrySet()) {
- NeutronRouter router = entry.getValue();
- allRouters.add(router);
- }
- LOGGER.debug("Exiting getAllRouters, Found {} Routers", allRouters.size());
- List<NeutronRouter> ans = new ArrayList<NeutronRouter>();
- ans.addAll(allRouters);
- return ans;
+ return getAll();
}
@Override
public boolean addRouter(NeutronRouter input) {
- if (routerExists(input.getID())) {
- return false;
- }
- routerDB.putIfAbsent(input.getID(), input);
- addMd(input);
- return true;
+ return add(input);
}
@Override
public boolean removeRouter(String uuid) {
- if (!routerExists(uuid)) {
- return false;
- }
- routerDB.remove(uuid);
- removeMd(toMd(uuid));
- return true;
+ return remove(uuid);
}
@Override
public boolean updateRouter(String uuid, NeutronRouter delta) {
- if (!routerExists(uuid)) {
- return false;
- }
- NeutronRouter target = routerDB.get(uuid);
- boolean rc = overwrite(target, delta);
- if (rc) {
- updateMd(routerDB.get(uuid));
- }
- return rc;
+ return update(uuid, delta);
}
@Override
public boolean routerInUse(String routerUUID) {
- if (!routerExists(routerUUID)) {
+ if (!exists(routerUUID)) {
return true;
}
- NeutronRouter target = routerDB.get(routerUUID);
+ NeutronRouter target = getRouter(routerUUID);
return (target.getInterfaces().size() > 0);
}
RouterBuilder routerBuilder = new RouterBuilder();
- if (router.getRouterUUID() != null) {
- routerBuilder.setUuid(toUuid(router.getRouterUUID()));
+ if (router.getID() != null) {
+ routerBuilder.setUuid(toUuid(router.getID()));
}
if (router.getName() != null) {
routerBuilder.setName(router.getName());
routerBuilder.setGatewayPortId(toUuid(router.getGatewayPortId()));
}
routerBuilder.setAdminStateUp(router.getAdminStateUp());
- routerBuilder.setDistribted(router.getDistributed());
+ routerBuilder.setDistributed(router.getDistributed());
if (router.getRoutes() != null) {
List<String> routes = new ArrayList<String>();
for (String route : router.getRoutes()) {
ExternalGatewayInfoBuilder builder = new ExternalGatewayInfoBuilder();
builder.setEnableSnat(externalGatewayInfos.getEnableSNAT());
builder.setExternalNetworkId(toUuid(externalGatewayInfos.getNetworkID()));
- List<ExternalFixedIps> externalFixedIps = new ArrayList<ExternalFixedIps>();
- for (int i = 0; i < externalFixedIps.size(); i++) {
- externalFixedIps.add((ExternalFixedIps) externalGatewayInfos.getExternalFixedIPs().get(i));
+ if (externalGatewayInfos.getExternalFixedIPs() != null) {
+ List<ExternalFixedIps> externalFixedIps = new ArrayList<ExternalFixedIps>();
+ for (Neutron_IPs eIP : externalGatewayInfos.getExternalFixedIPs()) {
+ ExternalFixedIpsBuilder eFixedIpBuilder = new ExternalFixedIpsBuilder();
+ eFixedIpBuilder.setIpAddress(new IpAddress(eIP.getIpAddress().toCharArray()));
+ eFixedIpBuilder.setSubnetId(toUuid(eIP.getSubnetUUID()));
+ externalFixedIps.add(eFixedIpBuilder.build());
+ }
+ builder.setExternalFixedIps(externalFixedIps);
}
- builder.setExternalFixedIps(externalFixedIps);
externalGatewayInfo = builder.build();
}
routerBuilder.setExternalGatewayInfo(externalGatewayInfo);
@Override
protected InstanceIdentifier<Router> createInstanceIdentifier(Router router) {
- return InstanceIdentifier.create(Neutron.class).child(Routers.class).child(Router.class, router.getKey());
+ return InstanceIdentifier.create(Neutron.class)
+ .child(Routers.class)
+ .child(Router.class, router.getKey());
+ }
+
+ @Override
+ protected InstanceIdentifier<Routers> createInstanceIdentifier() {
+ return InstanceIdentifier.create(Neutron.class).child(Routers.class);
}
@Override
public static void registerNewInterface(BundleContext context,
ProviderContext providerContext,
- List<ServiceRegistration<?>> registrations) throws Exception {
+ List<ServiceRegistration<?>> registrations) {
NeutronRouterInterface neutronRouterInterface = new NeutronRouterInterface(providerContext);
ServiceRegistration<INeutronRouterCRUD> neutronRouterInterfaceRegistration = context.registerService(INeutronRouterCRUD.class, neutronRouterInterface, null);
if(neutronRouterInterfaceRegistration != null) {
registrations.add(neutronRouterInterfaceRegistration);
}
}
+
+ public NeutronRouter fromMd(Router router) {
+ NeutronRouter result = new NeutronRouter();
+ result.setID(router.getUuid().getValue());
+ result.setName(router.getName());
+ result.setTenantID(router.getTenantId());
+ result.setAdminStateUp(router.isAdminStateUp());
+ result.setStatus(router.getStatus());
+ result.setDistributed(router.isDistributed());
+ if (router.getGatewayPortId() != null) {
+ result.setGatewayPortId(String.valueOf(router.getGatewayPortId().getValue()));
+ }
+ if (router.getRoutes() != null) {
+ List<String> routes = new ArrayList<String>();
+ for (String route : router.getRoutes()) {
+ routes.add(route);
+ }
+ result.setRoutes(routes);
+ }
+
+ if (router.getExternalGatewayInfo() != null) {
+ NeutronRouter_NetworkReference extGwInfo = new NeutronRouter_NetworkReference();
+ extGwInfo.setNetworkID(String.valueOf(router.getExternalGatewayInfo().getExternalNetworkId().getValue()));
+ extGwInfo.setEnableSNAT(router.getExternalGatewayInfo().isEnableSnat());
+ if (router.getExternalGatewayInfo().getExternalFixedIps() != null) {
+ List<Neutron_IPs> fixedIPs = new ArrayList<Neutron_IPs>();
+ for (ExternalFixedIps mdFixedIP : router.getExternalGatewayInfo().getExternalFixedIps()) {
+ Neutron_IPs fixedIP = new Neutron_IPs();
+ fixedIP.setSubnetUUID(String.valueOf(mdFixedIP.getSubnetId().getValue()));
+ fixedIP.setIpAddress(String.valueOf(mdFixedIP.getIpAddress().getValue()));
+ fixedIPs.add(fixedIP);
+ }
+ extGwInfo.setExternalFixedIPs(fixedIPs);
+ }
+ result.setExternalGatewayInfo(extGwInfo);
+ }
+
+ if (router.getInterfaces() != null) {
+ Map<String, NeutronRouter_Interface> interfaces = new HashMap<String, NeutronRouter_Interface>();
+ for (Interfaces mdInterface : router.getInterfaces()) {
+ NeutronRouter_Interface pojoInterface = new NeutronRouter_Interface();
+ String id = mdInterface.getUuid().getValue();
+ pojoInterface.setID(id);
+ pojoInterface.setTenantID(mdInterface.getTenantId());
+ pojoInterface.setSubnetUUID(String.valueOf(mdInterface.getSubnetId().getValue()));
+ pojoInterface.setPortUUID(String.valueOf(mdInterface.getPortId().getValue()));
+ interfaces.put(id, pojoInterface);
+ }
+ result.setInterfaces(interfaces);
+ }
+ return result;
+ }
}