use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.
the class DefaultMappingTreatmentTest method testBuilderMethods.
/**
* Tests method defined on the Builder.
*/
@Test
public void testBuilderMethods() {
IpPrefix ip = IpPrefix.valueOf(IP_ADDRESS_1);
MappingAddress address = MappingAddresses.ipv4MappingAddress(ip);
MappingTreatment.Builder builder = DefaultMappingTreatment.builder().withAddress(address).setUnicastPriority(10).setUnicastWeight(10);
MappingTreatment treatment = builder.build();
assertThat(treatment.instructions(), hasSize(2));
}
use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.
the class MappingKeyCodec method encode.
@Override
public ObjectNode encode(MappingKey key, CodecContext context) {
checkNotNull(key, "Mapping key cannot be null");
final ObjectNode result = context.mapper().createObjectNode();
final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
result.set(ADDRESS, addressCodec.encode(key.address(), context));
return result;
}
use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.
the class MappingsWebResourceTest method setupMockMappings.
/**
* Populates some mappings used as testing data.
*/
private void setupMockMappings() {
MappingAddress address1 = MappingAddresses.ipv4MappingAddress(IPV4_PREFIX_1);
MappingAddress address2 = MappingAddresses.ipv4MappingAddress(IPV4_PREFIX_2);
MappingInstruction unicastWeight1 = unicastWeight(UNICAST_WEIGHT);
MappingInstruction unicastPriority1 = unicastPriority(UNICAST_PRIORITY);
MappingInstruction multicastWeight1 = multicastWeight(MULTICAST_WEIGHT);
MappingInstruction multicastPriority1 = multicastPriority(MULTICAST_PRIORITY);
MappingInstruction unicastWeight2 = unicastWeight(UNICAST_WEIGHT + DIFF_VALUE);
MappingInstruction unicastPriority2 = unicastPriority(UNICAST_PRIORITY + DIFF_VALUE);
MappingInstruction multicastWeight2 = multicastWeight(MULTICAST_WEIGHT + DIFF_VALUE);
MappingInstruction multicastPriority2 = multicastPriority(MULTICAST_PRIORITY + DIFF_VALUE);
MappingKey key1 = DefaultMappingKey.builder().withAddress(address1).build();
MappingTreatment treatment1 = DefaultMappingTreatment.builder().add(unicastWeight1).add(unicastPriority1).add(multicastWeight1).add(multicastPriority1).withAddress(address1).build();
MappingAction action1 = MappingActions.noAction();
MappingValue value1 = DefaultMappingValue.builder().add(treatment1).withAction(action1).build();
MappingKey key2 = DefaultMappingKey.builder().withAddress(address2).build();
MappingTreatment treatment2 = DefaultMappingTreatment.builder().add(unicastWeight2).add(unicastPriority2).add(multicastWeight2).add(multicastPriority2).withAddress(address2).build();
MappingAction action2 = MappingActions.forward();
MappingValue value2 = DefaultMappingValue.builder().add(treatment2).withAction(action2).build();
mapping1.key = key1;
mapping2.key = key2;
mapping3.key = key1;
mapping4.key = key2;
mapping1.value = value1;
mapping2.value = value2;
mapping3.value = value1;
mapping4.value = value2;
final Set<MappingEntry> mappings1 = Sets.newHashSet();
mappings1.add(mapping1);
mappings1.add(mapping2);
final Set<MappingEntry> mappings2 = Sets.newHashSet();
mappings2.add(mapping3);
mappings2.add(mapping4);
mappings.put(deviceId1, mappings1);
mappings.put(deviceId2, mappings2);
}
use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.
the class MappingEntryBuilder method buildTreatments.
/**
* Builds a collection of mapping treatments.
*
* @param record LISP map record
* @return a collection of mapping treatments
*/
private List<MappingTreatment> buildTreatments(LispMapRecord record) {
List<LispLocator> locators = record.getLocators();
List<MappingTreatment> treatments = Lists.newArrayList();
for (LispLocator locator : locators) {
MappingTreatment.Builder builder = DefaultMappingTreatment.builder();
LispAfiAddress address = locator.getLocatorAfi();
final MappingAddress mappingAddress = getAddress(deviceService, deviceId, address);
if (mappingAddress != null) {
builder.withAddress(mappingAddress);
}
builder.setUnicastWeight(locator.getWeight()).setUnicastPriority(locator.getPriority()).setMulticastWeight(locator.getMulticastWeight()).setMulticastPriority(locator.getMulticastPriority());
// TODO: need to convert specific properties to
// abstracted extension properties
treatments.add(builder.build());
}
return treatments;
}
use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.
the class LispExtensionMappingAddressInterpreter method mapLcafAddress.
@Override
public ExtensionMappingAddress mapLcafAddress(LispLcafAddress lcafAddress) {
switch(lcafAddress.getType()) {
case LIST:
LispListLcafAddress lcafListAddress = (LispListLcafAddress) lcafAddress;
MappingAddress ipv4Ma = afi2mapping(lcafListAddress.getAddresses().get(0));
MappingAddress ipv6Ma = afi2mapping(lcafListAddress.getAddresses().get(1));
return new LispListAddress.Builder().withIpv4(ipv4Ma).withIpv6(ipv6Ma).build();
case SEGMENT:
LispSegmentLcafAddress segmentLcafAddress = (LispSegmentLcafAddress) lcafAddress;
return new LispSegmentAddress.Builder().withInstanceId(segmentLcafAddress.getInstanceId()).withAddress(getMappingAddress(segmentLcafAddress.getAddress())).build();
case AS:
LispAsLcafAddress asLcafAddress = (LispAsLcafAddress) lcafAddress;
return new org.onosproject.drivers.lisp.extensions.LispAsAddress.Builder().withAsNumber(asLcafAddress.getAsNumber()).withAddress(getMappingAddress(asLcafAddress.getAddress())).build();
case APPLICATION_DATA:
LispAppDataLcafAddress appLcafAddress = (LispAppDataLcafAddress) lcafAddress;
return new LispAppDataAddress.Builder().withProtocol(appLcafAddress.getProtocol()).withIpTos(appLcafAddress.getIpTos()).withLocalPortLow(appLcafAddress.getLocalPortLow()).withLocalPortHigh(appLcafAddress.getLocalPortHigh()).withRemotePortLow(appLcafAddress.getRemotePortLow()).withRemotePortHigh(appLcafAddress.getRemotePortHigh()).withAddress(getMappingAddress(appLcafAddress.getAddress())).build();
case GEO_COORDINATE:
LispGeoCoordinateLcafAddress gcLcafAddress = (LispGeoCoordinateLcafAddress) lcafAddress;
return new LispGcAddress.Builder().withIsNorth(gcLcafAddress.isNorth()).withLatitudeDegree(gcLcafAddress.getLatitudeDegree()).withLatitudeMinute(gcLcafAddress.getLatitudeMinute()).withLatitudeSecond(gcLcafAddress.getLatitudeSecond()).withIsEast(gcLcafAddress.isEast()).withLongitudeDegree(gcLcafAddress.getLongitudeDegree()).withLongitudeMinute(gcLcafAddress.getLongitudeMinute()).withLongitudeSecond(gcLcafAddress.getLongitudeSecond()).withAltitude(gcLcafAddress.getAltitude()).withAddress(getMappingAddress(gcLcafAddress.getAddress())).build();
case NAT:
LispNatLcafAddress natLcafAddress = (LispNatLcafAddress) lcafAddress;
List<MappingAddress> mas = Lists.newArrayList();
natLcafAddress.getRtrRlocAddresses().forEach(rtr -> mas.add(getMappingAddress(rtr)));
return new LispNatAddress.Builder().withMsUdpPortNumber(natLcafAddress.getMsUdpPortNumber()).withEtrUdpPortNumber(natLcafAddress.getEtrUdpPortNumber()).withMsRlocAddress(getMappingAddress(natLcafAddress.getMsRlocAddress())).withGlobalEtrRlocAddress(getMappingAddress(natLcafAddress.getGlobalEtrRlocAddress())).withPrivateEtrRlocAddress(getMappingAddress(natLcafAddress.getPrivateEtrRlocAddress())).withRtrRlocAddresses(mas).build();
case NONCE:
LispNonceLcafAddress nonceLcafAddress = (LispNonceLcafAddress) lcafAddress;
return new LispNonceAddress.Builder().withNonce(nonceLcafAddress.getNonce()).withAddress(getMappingAddress(nonceLcafAddress.getAddress())).build();
case MULTICAST:
LispMulticastLcafAddress multiLcafAddress = (LispMulticastLcafAddress) lcafAddress;
return new LispMulticastAddress.Builder().withInstanceId(multiLcafAddress.getInstanceId()).withSrcAddress(getMappingAddress(multiLcafAddress.getSrcAddress())).withSrcMaskLength(multiLcafAddress.getSrcMaskLength()).withGrpAddress(getMappingAddress(multiLcafAddress.getGrpAddress())).withGrpMaskLength(multiLcafAddress.getGrpMaskLength()).build();
case TRAFFIC_ENGINEERING:
LispTeLcafAddress teLcafAddress = (LispTeLcafAddress) lcafAddress;
List<LispTeAddress.TeRecord> records = Lists.newArrayList();
teLcafAddress.getTeRecords().forEach(record -> {
LispTeAddress.TeRecord teRecord = new LispTeAddress.TeRecord.Builder().withIsLookup(record.isLookup()).withIsRlocProbe(record.isRlocProbe()).withIsStrict(record.isStrict()).withRtrRlocAddress(getMappingAddress(record.getRtrRlocAddress())).build();
records.add(teRecord);
});
return new LispTeAddress.Builder().withTeRecords(records).build();
case SECURITY:
// TODO: need to implement security type later
log.warn("security type will be implemented later");
return null;
case SOURCE_DEST:
LispSourceDestLcafAddress srcDstLcafAddress = (LispSourceDestLcafAddress) lcafAddress;
return new LispSrcDstAddress.Builder().withSrcPrefix(getMappingAddress(srcDstLcafAddress.getSrcPrefix())).withSrcMaskLength(srcDstLcafAddress.getSrcMaskLength()).withDstPrefix(getMappingAddress(srcDstLcafAddress.getDstPrefix())).withDstMaskLength(srcDstLcafAddress.getDstMaskLength()).build();
case UNSPECIFIED:
case UNKNOWN:
default:
log.error("Unsupported LCAF type {}", lcafAddress.getType());
return null;
}
}
Aggregations