*/
package org.opendaylight.lispflowmapping.interfaces.lisp;
+import java.net.InetAddress;
+
import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapReply;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRequest;
/**
* An interface for dealing with a map reply message.
*/
-public interface IMapReplyHandler {
+public interface IMapRequestResultHandler {
public void handleMapReply(MapReply mapReply);
+
+ public void handleNonProxyMapRequest(MapRequest mapRequest, InetAddress targetAddress);
}
* The async map resolver interface for dealing with async map request calls.
*/
public interface IMapResolverAsync extends IGeneralMapResolver {
- public void handleMapRequest(MapRequest request, IMapReplyHandler callback);
+ public void handleMapRequest(MapRequest request, IMapRequestResultHandler callback);
}
import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapNotify;
import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapReply;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRequest;
import org.opendaylight.yangtools.yang.binding.RpcService;
import org.opendaylight.yangtools.yang.common.RpcResult;
*/
Future<RpcResult<java.lang.Void>> handleMapReply(MapReply mapReply, InetAddress targetAddress);
+ /**
+ * Handle a non proxy map request by sending it to the correct xTR.
+ *
+ * @param mapRequest
+ * @param targetAddress
+ * @return
+ */
+ Future<RpcResult<java.lang.Void>> handleMapRequest(MapRequest mapRequest, InetAddress targetAddress);
+
}
\ No newline at end of file
org.opendaylight.controller.sal.core,
org.apache.felix.dm,
org.apache.commons.lang3,
+ org.apache.commons.lang3.tuple,
org.apache.commons.lang3.builder,
org.osgi.service.component,
org.slf4j,
import java.net.InetAddress;
import java.net.UnknownHostException;
+import org.apache.commons.lang3.tuple.MutablePair;
+import org.apache.commons.lang3.tuple.Pair;
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor;
import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
import org.opendaylight.lispflowmapping.interfaces.lisp.IMapNotifyHandler;
-import org.opendaylight.lispflowmapping.interfaces.lisp.IMapReplyHandler;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IMapRequestResultHandler;
import org.opendaylight.lispflowmapping.interfaces.lisp.IMapResolverAsync;
import org.opendaylight.lispflowmapping.interfaces.lisp.IMapServerAsync;
import org.opendaylight.lispflowmapping.type.sbplugin.ILispSouthboundPlugin;
import com.google.common.net.InetAddresses;
public class LispMappingService implements CommandProvider, IFlowMapping, BindingAwareConsumer, //
- IMapReplyHandler, IMapNotifyHandler {
+ IMapRequestResultHandler, IMapNotifyHandler {
protected static final Logger logger = LoggerFactory.getLogger(LispMappingService.class);
private ILispDAO lispDao = null;
private volatile boolean shouldAuthenticate;
private ThreadLocal<MapReply> tlsMapReply = new ThreadLocal<MapReply>();
private ThreadLocal<MapNotify> tlsMapNotify = new ThreadLocal<MapNotify>();
+ private ThreadLocal<Pair<MapRequest, InetAddress>> tlsMapRequest = new ThreadLocal<Pair<MapRequest, InetAddress>>();
private ILispSouthboundPlugin lispSB = null;
public MapReply handleMapRequest(MapRequest request) {
tlsMapReply.set(null);
+ tlsMapRequest.set(null);
mapResolver.handleMapRequest(request, this);
// After this invocation we assume that the thread local is filled with
// the reply
- return tlsMapReply.get();
+ if (tlsMapRequest.get() != null) {
+ getLispSB().handleMapRequest(tlsMapRequest.get().getLeft(), tlsMapRequest.get().getRight());
+ return null;
+ } else {
+ return tlsMapReply.get();
+ }
}
public void handleMapNotify(MapNotify notify) {
tlsMapNotify.set(notify);
}
+
+ @Override
+ public void handleNonProxyMapRequest(MapRequest mapRequest, InetAddress targetAddress) {
+ tlsMapRequest.set(new MutablePair<MapRequest, InetAddress>(mapRequest, targetAddress));
+ }
+
}
import java.util.Map;
import org.opendaylight.lispflowmapping.implementation.dao.MappingServiceKeyUtil;
+import org.opendaylight.lispflowmapping.implementation.util.LispNotificationHelper;
import org.opendaylight.lispflowmapping.implementation.util.MaskUtil;
import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
import org.opendaylight.lispflowmapping.interfaces.dao.IMappingServiceKey;
import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceRLOC;
import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceValue;
-import org.opendaylight.lispflowmapping.interfaces.lisp.IMapReplyHandler;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IMapRequestResultHandler;
import org.opendaylight.lispflowmapping.interfaces.lisp.IMapResolverAsync;
import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRequest;
import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidrecords.EidRecord;
this.shouldIterateMask = iterateMask;
}
- public void handleMapRequest(MapRequest request, IMapReplyHandler callback) {
+ public void handleMapRequest(MapRequest request, IMapRequestResultHandler callback) {
if (dao == null) {
logger.warn("handleMapRequest called while dao is uninitialized");
+ return;
+ }
+ if (request.isPitr()) {
+ if (request.getEidRecord().size() > 0) {
+ EidRecord eid = request.getEidRecord().get(0);
+ Map<String, ?> locators = getLocators(eid);
+ MappingServiceValue value = (MappingServiceValue) locators.get("value");
+ if (value.getRlocs() != null && value.getRlocs().size() > 0) {
+ callback.handleNonProxyMapRequest(request,
+ LispNotificationHelper.getInetAddressFromContainer(value.getRlocs().get(0).getRecord().getLispAddressContainer()));
+ }
+ }
+
} else {
MapReplyBuilder builder = new MapReplyBuilder();
builder.setEchoNonceEnabled(false);
recordBuilder.setMaskLength(eid.getMask());
recordBuilder.setLispAddressContainer(eid.getLispAddressContainer());
recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
- IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(eid.getLispAddressContainer(), eid.getMask());
- Map<String, ?> locators = dao.get(key);
- if (shouldIterateMask() && locators == null && MaskUtil.isMaskable(key.getEID().getAddress())) {
- locators = findMaskLocators(key);
- }
+ Map<String, ?> locators = getLocators(eid);
if (locators != null) {
MappingServiceValue value = (MappingServiceValue) locators.get("value");
}
}
+ private Map<String, ?> getLocators(EidRecord eid) {
+ IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(eid.getLispAddressContainer(), eid.getMask());
+ Map<String, ?> locators = dao.get(key);
+ if (shouldIterateMask() && locators == null && MaskUtil.isMaskable(key.getEID().getAddress())) {
+ locators = findMaskLocators(key);
+ }
+ return locators;
+ }
+
private Map<String, ?> findMaskLocators(IMappingServiceKey key) {
int mask = key.getMask();
while (mask > 0) {
import java.net.InetAddress;
import java.net.UnknownHostException;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.LispAddressContainer;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.lispaddresscontainer.address.Ipv4;
import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.mapregisternotification.MapRegister;
import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.mapregisternotification.MapRegisterBuilder;
import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.maprequestnotification.MapRequest;
}
public static InetAddress getInetAddressFromIpAddress(IpAddress ipAddress) {
- InetAddress address = InetAddress.getLoopbackAddress();
- if (ipAddress == null) {
- return address;
- }
- if (ipAddress.getIpv4Address() != null) {
- try {
- address = Inet4Address.getByName(ipAddress.getIpv4Address().getValue());
- } catch (UnknownHostException e) {
- }
- } else if (ipAddress.getIpv6Address() != null) {
- try {
- address = Inet4Address.getByName(ipAddress.getIpv6Address().getValue());
- } catch (UnknownHostException e) {
+ InetAddress address = null;
+ if (ipAddress != null) {
+ if (ipAddress.getIpv4Address() != null) {
+ address = getAddressByName(ipAddress.getIpv4Address().getValue());
+ } else if (ipAddress.getIpv6Address() != null) {
+ address = getAddressByName(ipAddress.getIpv6Address().getValue());
}
}
+ if (address == null) {
+ address = InetAddress.getLoopbackAddress();
+ }
return address;
}
+
+ public static InetAddress getInetAddressFromContainer(LispAddressContainer container) {
+ Ipv4Address ipAddress = ((Ipv4) LispAFIConvertor.toAFI(container)).getIpv4Address();
+ return getAddressByName(ipAddress.getValue());
+ }
+
+ public static InetAddress getAddressByName(String IPAddress) {
+ try {
+ InetAddress address = InetAddress.getByName(IPAddress);
+ return address;
+ } catch (UnknownHostException e) {
+ return null;
+ }
+ }
}
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
</dependency>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-json</artifactId>
+ <version>${jersey.version}</version>
+ </dependency>
<dependency>
<groupId>org.opendaylight.yangtools.thirdparty</groupId>
<artifactId>xtend-lib-osgi</artifactId>
mavenBundle(JERSEY, "jersey-client").versionAsInProject(),
mavenBundle(JERSEY, "jersey-server").versionAsInProject().startLevel(2),
mavenBundle(JERSEY, "jersey-core").versionAsInProject().startLevel(2),
- // mavenBundle(JERSEY,
- // "jersey-json").versionAsInProject().startLevel(2),
+ mavenBundle(JERSEY, "jersey-json").versionAsInProject().startLevel(2),
mavenBundle("com.fasterxml.jackson.core", "jackson-annotations").versionAsInProject(),//
mavenBundle("com.fasterxml.jackson.core", "jackson-core").versionAsInProject(),//
mavenBundle("com.fasterxml.jackson.core", "jackson-databind").versionAsInProject(),//
// Retrieve the RLOC from the database
MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
+ mapRequestBuilder.setPitr(false);
mapRequestBuilder.setEidRecord(new ArrayList<EidRecord>());
mapRequestBuilder.getEidRecord().add(
new EidRecordBuilder().setMask((short) mask).setLispAddressContainer(LispAFIConvertor.toContainer(eid)).build());
return mr;
}
+ @Test
+ public void nonProxyTest() throws SocketTimeoutException, SocketException {
+ String eid = "10.0.0.1";
+ String rloc = "127.0.0.3";
+ MapRegister mr = createMapRegister(LispAFIConvertor.asIPAfiAddress(eid));
+ LocatorRecord record = new LocatorRecordBuilder(mr.getEidToLocatorRecord().get(0).getLocatorRecord().get(0)).setLispAddressContainer(
+ LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress(rloc))).build();
+ mr.getEidToLocatorRecord().get(0).getLocatorRecord().set(0, record);
+ sendMapRegister(mr);
+ receiveMapNotify();
+ MapRequest mapRequest = createMapRequest(LispAFIConvertor.asIPAfiAddress(eid));
+ MapRequestBuilder builder = new MapRequestBuilder(mapRequest);
+ builder.setPitr(true);
+ mapRequest = builder.build();
+ sendMapRequest(mapRequest);
+ socket = new DatagramSocket(new InetSocketAddress(rloc, LispMessage.PORT_NUM));
+ MapRequest recievedMapRequest = receiveMapRequest();
+ assertEquals(mapRequest.getNonce(), recievedMapRequest.getNonce());
+ assertEquals(mapRequest.getSourceEid(), recievedMapRequest.getSourceEid());
+ assertEquals(mapRequest.getItrRloc(), recievedMapRequest.getItrRloc());
+ assertEquals(mapRequest.getEidRecord(), recievedMapRequest.getEidRecord());
+
+ }
+
private MapReply receiveMapReply() throws SocketTimeoutException {
return MapReplySerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket().getData()));
}
+ private MapRequest receiveMapRequest() throws SocketTimeoutException {
+ return MapRequestSerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket().getData()));
+ }
+
private MapNotify receiveMapNotify() throws SocketTimeoutException {
return MapNotifySerializer.getInstance().deserialize(ByteBuffer.wrap(receivePacket().getData()));
}
import org.opendaylight.lispflowmapping.implementation.serializer.LispMessage;
import org.opendaylight.lispflowmapping.implementation.serializer.MapNotifySerializer;
import org.opendaylight.lispflowmapping.implementation.serializer.MapReplySerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.MapRequestSerializer;
import org.opendaylight.lispflowmapping.southbound.lisp.LispSouthboundService;
import org.opendaylight.lispflowmapping.type.sbplugin.IConfigLispPlugin;
import org.opendaylight.lispflowmapping.type.sbplugin.ILispSouthboundPlugin;
import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapNotify;
import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapReply;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRequest;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
private volatile DatagramSocket socket = null;
private final String MAP_NOTIFY = "MapNotify";
private final String MAP_REPlY = "MapReply";
+ private final String MAP_REQUEST = "MapRequest";
private volatile String bindingAddress = null;
private volatile boolean stillRunning = false;
private volatile boolean alreadyInit = false;
return null;
}
+ public Future<RpcResult<Void>> handleMapRequest(MapRequest mapRequest, InetAddress address) {
+ logger.trace("handleMapRequest called!!");
+ if (mapRequest != null) {
+ ByteBuffer outBuffer = MapRequestSerializer.getInstance().serialize(mapRequest);
+ handleSerializedLispBuffer(address, outBuffer, MAP_REQUEST);
+ } else {
+ logger.debug("MapRequest was null");
+ }
+ return null;
+ }
+
public void setLispAddress(String address) {
synchronized (startLock) {
if (bindingAddress != null && bindingAddress.equals(address)) {
/target
/META-INF
+/target