/*
- * Copyright (c) 2016 Cisco Systems, Inc. All rights reserved.
+ * Copyright (c) 2016, 2017 Cisco Systems, Inc. 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,
* Returns the parent prefix for given key.
*
* @param key
- * The key which parent is to be returned.
- * @return The parent perfix of a specific key.
+ * The key for which parent is to be returned.
+ * @return The parent prefix of a specific key.
*/
Eid getParentPrefix(Eid key);
+
+ /**
+ * Returns the sibling prefix for given key.
+ *
+ * @param key
+ * The key for which sibling is to be returned.
+ * @return The sibling prefix of a specific key.
+ */
+ Eid getSiblingPrefix(Eid key);
+
+ /**
+ * Returns the virtual parent sibling prefix for given key.
+ *
+ * @param key
+ * The key for which virtual parent sibling is to be returned.
+ * @return The virtual parent sibling prefix of a specific key.
+ */
+ Eid getVirtualParentSiblingPrefix(Eid key);
}
/*
- * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
+ * Copyright (c) 2015, 2017 Cisco Systems, Inc. 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,
*/
void addMapping(MappingOrigin origin, Eid key, MappingData mapping);
+ /**
+ * Generate and add a negative mapping entry originated from the southbound, and return the generated mapping.
+ *
+ * @param key
+ * Key of the mapping
+ * @return Returns the generated negative mapping (which is never null).
+ */
+ MappingData addNegativeMapping(Eid key);
+
/**
* Retrieves mapping for the provided src and dst key.
*
/*
- * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
+ * Copyright (c) 2015, 2017 Cisco Systems, Inc. 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,
*/
void addMapping(MappingOrigin origin, Eid key, SiteId siteId, MappingData mapping);
+ /**
+ * Generate and add a negative mapping entry originated from the southbound, and return the generated mapping.
+ *
+ * @param key
+ * Key of the mapping
+ * @return Returns the generated negative mapping (which is never null).
+ */
+ MappingData addNegativeMapping(Eid key);
+
/**
* Retrieves mapping with given origin for the provided key. The lookup policy for the key is defined in the Mapping
* System.
/*
- * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
+ * Copyright (c) 2015, 2017 Cisco Systems, Inc. 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,
LOG.info("Mapping Service initializing...");
dsbe = new DataStoreBackEnd(dataBroker);
- mappingSystem = new MappingSystem(dao, iterateMask, notificationPolicy, mappingMergePolicy);
+ mappingSystem = new MappingSystem(dao, iterateMask, notificationPublishService, mappingMergePolicy);
mappingSystem.setDataStoreBackEnd(dsbe);
mappingSystem.initialize();
}
}
+ @Override
+ public MappingData addNegativeMapping(Eid key) {
+ return mappingSystem.addNegativeMapping(key);
+ }
+
@Override
public void refreshMappingRegistration(Eid key, XtrId xtrId, Long timestamp) {
mappingSystem.refreshMappingRegistration(key, xtrId, timestamp);
/*
- * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
+ * Copyright (c) 2015, 2017 Cisco Systems, Inc. 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,
package org.opendaylight.lispflowmapping.implementation;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.ArrayList;
import java.util.Date;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.lispflowmapping.config.ConfigIni;
import org.opendaylight.lispflowmapping.dsbackend.DataStoreBackEnd;
import org.opendaylight.lispflowmapping.implementation.timebucket.implementation.TimeBucketMappingTimeoutService;
import org.opendaylight.lispflowmapping.implementation.timebucket.interfaces.ISouthBoundMappingTimeoutService;
import org.opendaylight.lispflowmapping.implementation.util.DSBEInputUtil;
+import org.opendaylight.lispflowmapping.implementation.util.MSNotificationInputUtil;
import org.opendaylight.lispflowmapping.implementation.util.MappingMergeUtil;
import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
+import org.opendaylight.lispflowmapping.interfaces.dao.Subscriber;
import org.opendaylight.lispflowmapping.interfaces.mapcache.IAuthKeyDb;
import org.opendaylight.lispflowmapping.interfaces.mapcache.ILispMapCache;
import org.opendaylight.lispflowmapping.interfaces.mapcache.IMapCache;
import org.opendaylight.lispflowmapping.interfaces.mapcache.IMappingSystem;
import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingService;
+import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
import org.opendaylight.lispflowmapping.lisp.type.MappingData;
import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
+import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
import org.opendaylight.lispflowmapping.mapcache.AuthKeyDb;
import org.opendaylight.lispflowmapping.mapcache.MultiTableMapCache;
import org.opendaylight.lispflowmapping.mapcache.SimpleMapCache;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ServicePath;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.explicit.locator.path.explicit.locator.path.Hop;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.IpAddressBinary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv4PrefixBinaryAfi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.Ipv6PrefixBinaryAfi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6PrefixBinary;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingChange;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping;
* mapping lookups.
*
* @author Florin Coras
+ * @author Lorand Jakab
*
*/
public class MappingSystem implements IMappingSystem {
private static final Logger LOG = LoggerFactory.getLogger(MappingSystem.class);
private static final String AUTH_KEY_TABLE = "authentication";
- private boolean notificationService;
+ private static final int TTL_RLOC_TIMED_OUT = 1;
+ private static final int TTL_NO_RLOC_KNOWN = 15;
+ private NotificationPublishService notificationPublishService;
private boolean mappingMerge;
private ILispDAO dao;
private ILispDAO sdao;
private ISouthBoundMappingTimeoutService sbMappingTimeoutService;
- public MappingSystem(ILispDAO dao, boolean iterateMask, boolean notifications, boolean mappingMerge) {
+ public MappingSystem(ILispDAO dao, boolean iterateMask, NotificationPublishService nps, boolean mappingMerge) {
this.dao = dao;
- this.notificationService = notifications;
+ this.notificationPublishService = nps;
this.mappingMerge = mappingMerge;
buildMapCaches();
smc.addData(key, SubKeys.TIME_BUCKET_ID, updatedBucketId);
}
+ @Override
+ public MappingData addNegativeMapping(Eid key) {
+ MappingRecord mapping = buildNegativeMapping(key);
+ MappingData mappingData = new MappingData(mapping);
+ smc.addMapping(mapping.getEid(), mappingData);
+ dsbe.addMapping(DSBEInputUtil.toMapping(MappingOrigin.Southbound, mapping.getEid(), null, mappingData));
+ return mappingData;
+ }
+
+ private MappingRecord buildNegativeMapping(Eid eid) {
+ MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
+ recordBuilder.setAuthoritative(false);
+ recordBuilder.setMapVersion((short) 0);
+ recordBuilder.setEid(eid);
+ if (eid.getAddressType().equals(Ipv4PrefixBinaryAfi.class)
+ || eid.getAddressType().equals(Ipv6PrefixBinaryAfi.class)) {
+ Eid widestNegativePrefix = getWidestNegativePrefix(eid);
+ if (widestNegativePrefix != null) {
+ recordBuilder.setEid(widestNegativePrefix);
+ }
+ }
+ recordBuilder.setAction(LispMessage.NEGATIVE_MAPPING_ACTION);
+ if (getAuthenticationKey(eid) != null) {
+ recordBuilder.setRecordTtl(TTL_RLOC_TIMED_OUT);
+ } else {
+ recordBuilder.setRecordTtl(TTL_NO_RLOC_KNOWN);
+ }
+ return recordBuilder.build();
+ }
+
/*
* Since this method is only called when there is a hit in the southbound Map-Register cache, and that cache is
* not used when merge is on, it's OK to ignore the effects of timestamp changes on merging for now.
@Override
public void removeMapping(MappingOrigin origin, Eid key) {
+ Set<Subscriber> subscribers = null;
if (origin == MappingOrigin.Southbound) {
removeFromSbTimeoutService(key);
+ MappingData mapping = (MappingData) smc.getMapping(null, key);
+ if (mapping != null && !mapping.isNegative()) {
+ SimpleImmutableEntry<Eid, Set<Subscriber>> mergedNegativePrefix = computeMergedNegativePrefix(key);
+ if (mergedNegativePrefix != null) {
+ addNegativeMapping(mergedNegativePrefix.getKey());
+ subscribers = mergedNegativePrefix.getValue();
+ try {
+ notificationPublishService.putNotification(
+ MSNotificationInputUtil.toMappingChanged(mapping, subscribers, MappingChange.Created));
+ } catch (InterruptedException e) {
+ LOG.warn("Notification publication interrupted!");
+ }
+ }
+ }
}
tableMap.get(origin).removeMapping(key);
- if (notificationService) {
- // TODO
+ }
+
+ @SuppressWarnings("unchecked")
+ /*
+ * Returns the "merged" prefix and the subscribers of the prefixes that were merged.
+ */
+ private SimpleImmutableEntry<Eid, Set<Subscriber>> computeMergedNegativePrefix(Eid eid) {
+ // Variable to hold subscribers we collect along the way
+ Set<Subscriber> subscribers = null;
+
+ // If prefix sibling has a negative mapping, save its subscribers
+ Eid sibling = smc.getSiblingPrefix(eid);
+ MappingData mapping = (MappingData) smc.getMapping(null, sibling);
+ if (mapping != null && mapping.isNegative()) {
+ subscribers = (Set<Subscriber>) getData(MappingOrigin.Southbound, eid, SubKeys.SUBSCRIBERS);
+ } else {
+ return null;
+ }
+
+ Eid currentNode = sibling;
+ Eid previousNode = sibling;
+ while ((currentNode = smc.getVirtualParentSiblingPrefix(currentNode)) != null) {
+ mapping = (MappingData) smc.getMapping(null, currentNode);
+ if (mapping != null && mapping.isNegative()) {
+ subscribers.addAll((Set<Subscriber>)
+ getData(MappingOrigin.Southbound, currentNode, SubKeys.SUBSCRIBERS));
+ removeSbMapping(currentNode, mapping);
+ } else {
+ break;
+ }
+ previousNode = currentNode;
+ }
+ return new SimpleImmutableEntry<>(getVirtualParent(previousNode), subscribers);
+ }
+
+ private static Eid getVirtualParent(Eid eid) {
+ if (eid.getAddress() instanceof Ipv4PrefixBinary) {
+ Ipv4PrefixBinary prefix = (Ipv4PrefixBinary) eid.getAddress();
+ short parentPrefixLength = (short) (prefix.getIpv4MaskLength() - 1);
+ byte[] parentPrefix = MaskUtil.normalizeByteArray(prefix.getIpv4AddressBinary().getValue(),
+ parentPrefixLength);
+ return LispAddressUtil.asIpv4PrefixBinaryEid(eid, parentPrefix, parentPrefixLength);
+ } else if (eid.getAddress() instanceof Ipv6PrefixBinary) {
+ Ipv6PrefixBinary prefix = (Ipv6PrefixBinary) eid.getAddress();
+ short parentPrefixLength = (short) (prefix.getIpv6MaskLength() - 1);
+ byte[] parentPrefix = MaskUtil.normalizeByteArray(prefix.getIpv6AddressBinary().getValue(),
+ parentPrefixLength);
+ return LispAddressUtil.asIpv6PrefixBinaryEid(eid, parentPrefix, parentPrefixLength);
}
+ return null;
}
@Override
/*
- * Copyright (c) 2014 Contextream, Inc. and others. All rights reserved.
+ * Copyright (c) 2014, 2017 Contextream, Inc. 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 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord.Action;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder;
public class MapResolver implements IMapResolverAsync {
protected static final Logger LOG = LoggerFactory.getLogger(MapResolver.class);
- private static final int TTL_RLOC_TIMED_OUT = 1;
- private static final int TTL_NO_RLOC_KNOWN = 15;
-
private IMappingService mapService;
private boolean subscriptionService;
private String elpPolicy;
MappingData mappingData = mapService.getMapping(srcEid, eidRecord.getEid());
MappingRecord mapping;
if (mappingData == null) {
- mapping = getNegativeMapping(eidRecord.getEid());
- mapService.addMapping(MappingOrigin.Southbound, mapping.getEid(), null, new MappingData(mapping));
+ mapping = mapService.addNegativeMapping(eidRecord.getEid()).getRecord();
} else {
mapping = mappingData.getRecord();
}
}
}
- private MappingRecord getNegativeMapping(Eid eid) {
- MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
- recordBuilder.setAuthoritative(false);
- recordBuilder.setMapVersion((short) 0);
- recordBuilder.setEid(eid);
- if (eid.getAddressType().equals(Ipv4PrefixBinaryAfi.class)
- || eid.getAddressType().equals(Ipv6PrefixBinaryAfi.class)) {
- Eid widestNegativePrefix = mapService.getWidestNegativePrefix(eid);
- if (widestNegativePrefix != null) {
- recordBuilder.setEid(widestNegativePrefix);
- }
- }
- recordBuilder.setAction(Action.NativelyForward);
- if (authenticate && mapService.getAuthenticationKey(eid) != null) {
- recordBuilder.setRecordTtl(TTL_RLOC_TIMED_OUT);
- } else {
- recordBuilder.setRecordTtl(TTL_NO_RLOC_KNOWN);
- }
- return recordBuilder.build();
- }
-
private void updateSubscribers(Rloc itrRloc, Eid reqEid, Eid mapEid, Eid srcEid, Integer recordTtl) {
Subscriber subscriber = new Subscriber(itrRloc, srcEid, Subscriber.recordTtlToSubscriberTime(recordTtl));
Eid subscribedEid = mapEid;
/*
- * Copyright (c) 2014 Contextream, Inc. and others. All rights reserved.
+ * Copyright (c) 2014, 2017 Contextream, Inc. 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 org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
import org.opendaylight.lispflowmapping.lisp.util.MapNotifyBuilderHelper;
import org.opendaylight.lispflowmapping.lisp.util.MapRequestUtil;
+import org.opendaylight.lispflowmapping.lisp.util.MappingRecordUtil;
import org.opendaylight.lispflowmapping.lisp.util.SourceDestKeyHelper;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey;
@SuppressWarnings("unchecked")
public void handleMapRegister(MapRegister mapRegister) {
boolean mappingUpdated = false;
+ boolean oldMappingRemoved = false;
boolean merge = ConfigIni.getInstance().mappingMergeIsSet() && mapRegister.isMergeEnabled();
Set<Subscriber> subscribers = null;
MappingRecord oldMapping;
oldMapping = getMappingRecord(mapService.getMapping(MappingOrigin.Southbound, eid));
mapService.addMapping(MappingOrigin.Southbound, eid, getSiteId(mapRegister), mappingData);
+ if (oldMapping != null && MappingRecordUtil.isNegativeMapping(oldMapping)) {
+ mapService.removeMapping(MappingOrigin.Southbound, oldMapping.getEid());
+ oldMappingRemoved = true;
+ }
if (subscriptionService) {
MappingRecord newMapping = merge
subscribers = addParentSubscribers(eid, subscribers);
}
sendSmrs(eid, subscribers);
+ if (oldMapping != null && oldMappingRemoved && !oldMapping.getEid().equals(eid)) {
+ subscribers = getSubscribers(oldMapping.getEid());
+ sendSmrs(oldMapping.getEid(), subscribers);
+ }
mappingUpdated = true;
}
}
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.lispflowmapping.config.ConfigIni;
import org.opendaylight.lispflowmapping.dsbackend.DataStoreBackEnd;
@Mock private static IMapCache pmcMock;
@Mock private static IAuthKeyDb akdbMock;
@Mock private static DataStoreBackEnd dsbeMock;
+ @Mock private static NotificationPublishService npsMock;
@Mock private static EnumMap<MappingOrigin, IMapCache> tableMapMock;
- @InjectMocks private static MappingSystem mappingSystem = new MappingSystem(daoMock, false, true, true);
+ @InjectMocks private static MappingSystem mappingSystem = new MappingSystem(daoMock, false, npsMock, true);
private static final String IPV4_SRC = "127.0.0.1";
private static final String IPV4_DST = "192.168.0.1";
*/
@Test
public void removeMappingTest_sb() throws NoSuchFieldException, IllegalAccessException {
- mappingSystem = new MappingSystem(daoMock, false, true, false);
+ mappingSystem = new MappingSystem(daoMock, false, npsMock, false);
injectMocks();
Mockito.when(tableMapMock.get(MappingOrigin.Southbound)).thenReturn(smcMock);
Mockito.verify(smcMock).printMappings();
mappingSystem.destroy();
- mappingSystem = new MappingSystem(daoMock, true, true, true);
+ mappingSystem = new MappingSystem(daoMock, true, npsMock, true);
mappingSystem.setDataStoreBackEnd(dsbeMock);
mappingSystem.setMappingMerge(false);
mappingSystem.setIterateMask(true);
/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2016, 2017 Cisco Systems, Inc. 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 org.opendaylight.lispflowmapping.implementation.MappingService;
import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
import org.opendaylight.lispflowmapping.interfaces.dao.Subscriber;
+import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
import org.opendaylight.lispflowmapping.lisp.type.MappingData;
import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
import org.opendaylight.lispflowmapping.lisp.util.SourceDestKeyHelper;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkeyBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder;
.setAuthoritative(false)
.setMapVersion((short) 0)
.setEid(IPV4_PREFIX_EID_1)
- .setAction(MappingRecord.Action.NativelyForward)
+ .setAction(LispMessage.NEGATIVE_MAPPING_ACTION)
.setRecordTtl(TTL_RLOC_TIMED_OUT);
Mockito.when(mapServiceMock.getMapping(mapRequestBuilder.getSourceEid().getEid(), IPV4_PREFIX_EID_1))
.thenReturn(null);
- Mockito.when(mapServiceMock.getAuthenticationKey(IPV4_PREFIX_EID_1))
- .thenReturn(new MappingAuthkeyBuilder().build());
- Mockito.when(mapServiceMock.getWidestNegativePrefix(IPV4_PREFIX_EID_1)).thenReturn(IPV4_PREFIX_EID_1);
+ Mockito.when(mapServiceMock.addNegativeMapping(IPV4_PREFIX_EID_1))
+ .thenReturn(getDefaultMappingData(mappingRecordBuilder.build()));
// result
final MapReplyBuilder mapReplyBuilder = getDefaultMapReplyBuilder();
/*
- * Copyright (c) 2014 Contextream, Inc. and others. All rights reserved.
+ * Copyright (c) 2014, 2017 Contextream, Inc. 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,
package org.opendaylight.lispflowmapping.lisp.type;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord.Action;
+
public interface LispMessage {
int PORT_NUM = 4342;
int XTR_PORT_NUM = 4343;
+ Action NEGATIVE_MAPPING_ACTION = Action.NativelyForward;
interface Pos {
int TYPE = 0;
/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2016, 2017 Cisco Systems, Inc. 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,
package org.opendaylight.lispflowmapping.lisp.type;
import java.util.Date;
+import org.opendaylight.lispflowmapping.lisp.util.MappingRecordUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
this.mergeEnabled = mergeEnabled;
}
+ public Boolean isNegative() {
+ if (record != null) {
+ return MappingRecordUtil.isNegativeMapping(record);
+ } else {
+ return null;
+ }
+ }
+
+ public Boolean isPositive() {
+ if (record != null) {
+ return MappingRecordUtil.isPositiveMapping(record);
+ } else {
+ return null;
+ }
+ }
+
@Override
public String toString() {
StringBuilder sb = new StringBuilder("MappingData [");
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems, Inc. 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.lispflowmapping.lisp.util;
+
+import java.util.List;
+import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Utility class for MappingRecord objects.
+ *
+ * @author Lorand Jakab
+ *
+ */
+public final class MappingRecordUtil {
+ protected static final Logger LOG = LoggerFactory.getLogger(MappingRecordUtil.class);
+
+ // Utility class, should not be instantiated
+ private MappingRecordUtil() {
+ }
+
+ public static boolean isNegativeMapping(MappingRecord mapping) {
+ List<LocatorRecord> rlocs = mapping.getLocatorRecord();
+ if (mapping.getAction() == LispMessage.NEGATIVE_MAPPING_ACTION && (rlocs == null || rlocs.isEmpty())) {
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isPositiveMapping(MappingRecord mapping) {
+ return !isNegativeMapping(mapping);
+ }
+}
/*
- * Copyright (c) 2014 Contextream, Inc. and others. All rights reserved.
+ * Copyright (c) 2014, 2017 Contextream, Inc. 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,
return InetAddress.getByAddress(normalizeByteArray(address.getAddress(), (short) maskLength));
}
- private static byte[] normalizeByteArray(byte[] address, short maskLength) {
+ public static byte[] normalizeByteArray(byte[] address, short maskLength) {
ByteBuffer byteRepresentation = ByteBuffer.wrap(address);
byte byteMask = (byte) 0xff;
int mask = maskLength;
/*
- * Copyright (c) 2015, 2016 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2015, 2017 Cisco Systems, Inc. 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,
@Override
public Eid getParentPrefix(Eid eid) {
- Eid key = MaskUtil.normalize(eid);
- ILispDAO table = getVniTable(key);
+ ILispDAO table = getVniTable(eid);
+ if (table == null) {
+ return null;
+ }
+ return table.getParentPrefix(MaskUtil.normalize(eid));
+ }
+
+ @Override
+ public Eid getSiblingPrefix(Eid eid) {
+ ILispDAO table = getVniTable(eid);
if (table == null) {
return null;
}
- return table.getParentPrefix(key);
+ return table.getSiblingPrefix(MaskUtil.normalize(eid));
+ }
+
+ @Override
+ public Eid getVirtualParentSiblingPrefix(Eid eid) {
+ ILispDAO table = getVniTable(eid);
+ if (table == null) {
+ return null;
+ }
+ return table.getVirtualParentSiblingPrefix(MaskUtil.normalize(eid));
}
@Override
public void removeMapping(Eid eid) {
- Eid key = MaskUtil.normalize(eid);
- ILispDAO table = getVniTable(key);
+ ILispDAO table = getVniTable(eid);
if (table == null) {
return;
}
+ Eid key = MaskUtil.normalize(eid);
// We intentionally don't remove subscribers, so in case a mapping is re-added, they get notified
table.removeSpecific(key, SubKeys.RECORD);
table.removeSpecific(key, SubKeys.SRC_RLOCS);
@Override
public void removeMapping(Eid eid, XtrId xtrId) {
- Eid key = MaskUtil.normalize(eid);
- ILispDAO table = getVniTable(key);
+ ILispDAO table = getVniTable(eid);
if (table == null) {
return;
}
+ Eid key = MaskUtil.normalize(eid);
ILispDAO xtrIdTable = (ILispDAO) table.getSpecific(key, SubKeys.XTRID_RECORDS);
if (xtrIdTable == null) {
return;
@Override
public void removeXtrIdMappings(Eid eid, List<XtrId> xtrIds) {
- Eid key = MaskUtil.normalize(eid);
- ILispDAO table = getVniTable(key);
+ ILispDAO table = getVniTable(eid);
if (table == null) {
return;
}
+ Eid key = MaskUtil.normalize(eid);
ILispDAO xtrIdTable = (ILispDAO) table.getSpecific(key, SubKeys.XTRID_RECORDS);
if (xtrIdTable == null) {
return;
@Override
public void addData(Eid eid, String subKey, Object data) {
+ ILispDAO table = getOrInstantiateVniTable(eid);
Eid key = MaskUtil.normalize(eid);
- ILispDAO table = getOrInstantiateVniTable(key);
table.put(key, new MappingEntry<>(subKey, data));
}