package org.opendaylight.lispflowmapping.interfaces.dao;
import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
+import org.opendaylight.lispflowmapping.type.lisp.MapReplyAction;
public class MappingServiceRLOC {
-
+
private LocatorRecord record;
private int ttl;
-
- public MappingServiceRLOC(LocatorRecord record, int ttl) {
+ private MapReplyAction action;
+ private boolean authoritative;
+
+ public MappingServiceRLOC(LocatorRecord record, int ttl, MapReplyAction action, boolean authoritative) {
super();
this.record = record;
this.ttl = ttl;
+ this.action = action;
+ this.authoritative = authoritative;
}
+
public LocatorRecord getRecord() {
return record;
}
+
public void setRecord(LocatorRecord record) {
this.record = record;
}
+
public int getTtl() {
return ttl;
}
+
public void setTtl(int ttl) {
this.ttl = ttl;
}
+
+ public MapReplyAction getAction() {
+ return action;
+ }
+
+ public void setAction(MapReplyAction action) {
+ this.action = action;
+ }
+
+ public boolean isAuthoritative() {
+ return authoritative;
+ }
+
+ public void setAuthoritative(boolean authoritative) {
+ this.authoritative = authoritative;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
+ result = prime * result + ((action == null) ? 0 : action.hashCode());
+ result = prime * result + (authoritative ? 1231 : 1237);
result = prime * result + ((record == null) ? 0 : record.hashCode());
result = prime * result + ttl;
return result;
}
+
@Override
public boolean equals(Object obj) {
if (this == obj)
if (getClass() != obj.getClass())
return false;
MappingServiceRLOC other = (MappingServiceRLOC) obj;
+ if (action != other.action)
+ return false;
+ if (authoritative != other.authoritative)
+ return false;
if (record == null) {
if (other.record != null)
return false;
return false;
return true;
}
-
+
@Override
public String toString() {
return record.getLocator().toString();
import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
import org.opendaylight.lispflowmapping.type.lisp.MapReply;
+import org.opendaylight.lispflowmapping.type.lisp.MapReplyAction;
import org.opendaylight.lispflowmapping.type.lisp.MapRequest;
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
mapRequest.addEidRecord(new EidRecord((byte) 0, new LispIpv4Address("1.2.3.4")));
EidToLocatorRecord record = new EidToLocatorRecord().setPrefix(v4Address);
- record.addLocator(new LocatorRecord().setLocator(new LispIpv4Address(0x04030201)));
+ LocatorRecord locator = new LocatorRecord().setLocator(new LispIpv4Address(0x04030201));
+ locator.setLocalLocator(false);
+ locator.setRouted(true);
+ locator.setMulticastPriority((byte) 5);
+ locator.setMulticastWeight((byte) 17);
+ locator.setPriority((byte) 16);
+ record.addLocator(locator);
prepareMapping(record);
MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest);
EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecords().get(0);
assertEquals(1, eidToLocators.getLocators().size());
+ LocatorRecord resultLocator = mapReply.getEidToLocatorRecords().get(0).getLocators().get(0);
+ assertEquals(locator.isLocalLocator(), resultLocator.isLocalLocator());
+ assertEquals(locator.isRouted(), resultLocator.isRouted());
+ assertEquals(locator.getMulticastPriority(), resultLocator.getMulticastPriority());
+ assertEquals(locator.getMulticastWeight(), resultLocator.getMulticastWeight());
+ assertEquals(locator.getPriority(), resultLocator.getPriority());
assertLocator(new LispIpv4Address(0x04030201), eidToLocators.getLocators().get(0));
}
- private Map<String, MappingServiceValue> prepareMapping(EidToLocatorRecord... records) {
- if (records.length > 0) {
- for (EidToLocatorRecord eidToLocatorRecord : records) {
- MappingServiceValue value = new MappingServiceValue();
- Map<String, MappingServiceValue> result = new HashMap<String, MappingServiceValue>();
- result.put("value", value);
- List<MappingServiceRLOC> rlocs = new ArrayList<MappingServiceRLOC>();
- for (LocatorRecord locator : eidToLocatorRecord.getLocators()) {
- rlocs.add(new MappingServiceRLOC(locator, eidToLocatorRecord.getRecordTtl()));
- }
- value.setRlocs(rlocs);
-
- daoResults.put(
- MappingServiceKeyUtil.generateMappingServiceKey(eidToLocatorRecord.getPrefix(), (byte) eidToLocatorRecord.getMaskLength()),
- result);
- }
- }
-
- ValueSaverAction<IMappingServiceKey> daoGetSaverAction = new ValueSaverAction<IMappingServiceKey>() {
- @Override
- protected boolean validate(IMappingServiceKey value) {
- return true;
- }
-
- @Override
- public Object invoke(Invocation invocation) throws Throwable {
- return daoResults.get(lastValue);
- }
- };
-
- allowing(lispDAO).get(with(daoGetSaverAction));
- will(daoGetSaverAction);
-
- return daoResults.get(MappingServiceKeyUtil.generateMappingServiceKey(v4Address));
- }
-
@Test
public void handleMapRequest__VerifyBasicFields() throws Exception {
mapRequest.addEidRecord(new EidRecord((byte) 0, v4Address));
EidToLocatorRecord record = new EidToLocatorRecord().setPrefix(v4Address);
+ record.setAction(MapReplyAction.NativelyForward);
+ record.setAuthoritative(true);
record.addLocator(new LocatorRecord().setLocator(new LispIpv4Address(0x04030201)));
prepareMapping(record);
EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecords().get(0);
assertEquals((byte) 0, eidToLocators.getMaskLength());
assertEquals(v4Address, eidToLocators.getPrefix());
+ assertEquals(record.isAuthoritative(), eidToLocators.isAuthoritative());
+ assertEquals(record.getAction(), eidToLocators.getAction());
+ assertEquals(record.getRecordTtl(), eidToLocators.getRecordTtl());
}
@Test
assertEquals(1, eidToLocators2.getLocators().size());
assertLocator(new LispIpv6Address("0:0:0:0:0:0:0:1"), eidToLocators2.getLocators().get(0));
}
+
+ private Map<String, MappingServiceValue> prepareMapping(EidToLocatorRecord... records) {
+ if (records.length > 0) {
+ for (EidToLocatorRecord eidToLocatorRecord : records) {
+ MappingServiceValue value = new MappingServiceValue();
+ Map<String, MappingServiceValue> result = new HashMap<String, MappingServiceValue>();
+ result.put("value", value);
+ List<MappingServiceRLOC> rlocs = new ArrayList<MappingServiceRLOC>();
+ for (LocatorRecord locator : eidToLocatorRecord.getLocators()) {
+ rlocs.add(new MappingServiceRLOC(locator, eidToLocatorRecord.getRecordTtl(), eidToLocatorRecord.getAction(), eidToLocatorRecord
+ .isAuthoritative()));
+ }
+ value.setRlocs(rlocs);
+
+ daoResults.put(
+ MappingServiceKeyUtil.generateMappingServiceKey(eidToLocatorRecord.getPrefix(), (byte) eidToLocatorRecord.getMaskLength()),
+ result);
+ }
+ }
+
+ ValueSaverAction<IMappingServiceKey> daoGetSaverAction = new ValueSaverAction<IMappingServiceKey>() {
+ @Override
+ protected boolean validate(IMappingServiceKey value) {
+ return true;
+ }
+
+ @Override
+ public Object invoke(Invocation invocation) throws Throwable {
+ return daoResults.get(lastValue);
+ }
+ };
+
+ allowing(lispDAO).get(with(daoGetSaverAction));
+ will(daoGetSaverAction);
+
+ return daoResults.get(MappingServiceKeyUtil.generateMappingServiceKey(v4Address));
+ }
}