Search in sources :

Example 1 with LispIpv4Address

use of org.onosproject.lisp.msg.types.LispIpv4Address in project onos by opennetworkinglab.

the class LispExtensionMappingAddressInterpreter method afi2mapping.

/**
 * Converts AFI address to generalized mapping address.
 *
 * @param afi IP typed AFI address
 * @return generalized mapping address
 */
private MappingAddress afi2mapping(LispAfiAddress afi) {
    switch(afi.getAfi()) {
        case IP4:
            IpAddress ipv4Address = ((LispIpv4Address) afi).getAddress();
            IpPrefix ipv4Prefix = IpPrefix.valueOf(ipv4Address, IPV4_PREFIX_LENGTH);
            return MappingAddresses.ipv4MappingAddress(ipv4Prefix);
        case IP6:
            IpAddress ipv6Address = ((LispIpv6Address) afi).getAddress();
            IpPrefix ipv6Prefix = IpPrefix.valueOf(ipv6Address, IPV6_PREFIX_LENGTH);
            return MappingAddresses.ipv6MappingAddress(ipv6Prefix);
        default:
            log.warn("Only support to convert IP address type");
            break;
    }
    return null;
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) LispIpv6Address(org.onosproject.lisp.msg.types.LispIpv6Address) LispIpv4Address(org.onosproject.lisp.msg.types.LispIpv4Address) IpAddress(org.onlab.packet.IpAddress)

Example 2 with LispIpv4Address

use of org.onosproject.lisp.msg.types.LispIpv4Address in project onos by opennetworkinglab.

the class LispMapServer method processInfoRequest.

/**
 * Handles info-request message and replies with info-reply message.
 *
 * @param message info-request message
 * @return info-reply message
 */
LispInfoReply processInfoRequest(LispMessage message) {
    LispInfoRequest request = (LispInfoRequest) message;
    if (!checkInfoRequestAuthData(request)) {
        log.warn(INVALID_AUTHENTICATION_DATA_MSG, "Info-Request");
        return null;
    }
    NatAddressBuilder natBuilder = new NatAddressBuilder();
    try {
        LispAfiAddress msAddress = new LispIpv4Address(valueOf(InetAddress.getLocalHost()));
        natBuilder.withMsRlocAddress(msAddress);
        natBuilder.withMsUdpPortNumber((short) INFO_REPLY_PORT);
        // try to extract global ETR RLOC address from info-request
        IpAddress globalRlocIp = valueOf(request.getSender().getAddress());
        LispAfiAddress globalRlocAddress;
        if (globalRlocIp.isIp4()) {
            globalRlocAddress = new LispIpv4Address(globalRlocIp);
        } else {
            globalRlocAddress = new LispIpv6Address(globalRlocIp);
        }
        natBuilder.withGlobalEtrRlocAddress(globalRlocAddress);
        natBuilder.withEtrUdpPortNumber((short) request.getSender().getPort());
        natBuilder.withPrivateEtrRlocAddress(new LispNoAddress());
    // TODO: need to specify RTR addresses
    } catch (UnknownHostException e) {
        log.warn(FAILED_TO_FORMULATE_NAT_MSG, e);
    }
    InfoReplyBuilder replyBuilder = new DefaultInfoReplyBuilder();
    replyBuilder.withKeyId(request.getKeyId());
    replyBuilder.withAuthDataLength(valueOf(authConfig.lispAuthKeyId()).getHashLength());
    replyBuilder.withAuthKey(authConfig.lispAuthKey());
    replyBuilder.withNonce(request.getNonce());
    replyBuilder.withEidPrefix(request.getPrefix());
    replyBuilder.withMaskLength(request.getMaskLength());
    replyBuilder.withTtl(request.getTtl());
    replyBuilder.withNatLcafAddress(natBuilder.build());
    replyBuilder.withIsInfoReply(true);
    LispInfoReply reply = replyBuilder.build();
    reply.configSender(request.getSender());
    return reply;
}
Also used : NatAddressBuilder(org.onosproject.lisp.msg.types.lcaf.LispNatLcafAddress.NatAddressBuilder) DefaultInfoReplyBuilder(org.onosproject.lisp.msg.protocols.DefaultLispInfoReply.DefaultInfoReplyBuilder) LispIpv6Address(org.onosproject.lisp.msg.types.LispIpv6Address) LispInfoRequest(org.onosproject.lisp.msg.protocols.LispInfoRequest) LispNoAddress(org.onosproject.lisp.msg.types.LispNoAddress) UnknownHostException(java.net.UnknownHostException) LispIpv4Address(org.onosproject.lisp.msg.types.LispIpv4Address) InfoReplyBuilder(org.onosproject.lisp.msg.protocols.LispInfoReply.InfoReplyBuilder) DefaultInfoReplyBuilder(org.onosproject.lisp.msg.protocols.DefaultLispInfoReply.DefaultInfoReplyBuilder) IpAddress(org.onlab.packet.IpAddress) LispAfiAddress(org.onosproject.lisp.msg.types.LispAfiAddress) LispInfoReply(org.onosproject.lisp.msg.protocols.LispInfoReply)

Example 3 with LispIpv4Address

use of org.onosproject.lisp.msg.types.LispIpv4Address in project onos by opennetworkinglab.

the class LispMapServer method sendSmrMessage.

/**
 * Sends SMR (Solicit Map Request) to their subscribers.
 *
 * @param eidRecord the updated EID
 */
private void sendSmrMessage(LispEidRecord eidRecord) {
    RequestBuilder builder = new DefaultRequestBuilder();
    LispAfiAddress msAddress = null;
    try {
        msAddress = new LispIpv4Address(IpAddress.valueOf(InetAddress.getLocalHost()));
    } catch (UnknownHostException e) {
        log.warn("Source EID is not found, {}", e.getMessage());
    }
    LispMapRequest msg = builder.withIsSmr(true).withIsSmrInvoked(true).withIsProbe(false).withIsPitr(false).withIsAuthoritative(false).withIsMapDataPresent(false).withSourceEid(msAddress).withEidRecords(ImmutableList.of(eidRecord)).build();
    LispRouterFactory routerFactory = LispRouterFactory.getInstance();
    Collection<LispRouter> routers = routerFactory.getRouters();
    routers.forEach(router -> {
        if (isInEidRecordRange(eidRecord, router.getEidRecords())) {
            router.sendMessage(msg);
        }
    });
}
Also used : LispRouter(org.onosproject.lisp.ctl.LispRouter) DefaultRequestBuilder(org.onosproject.lisp.msg.protocols.DefaultLispMapRequest.DefaultRequestBuilder) RequestBuilder(org.onosproject.lisp.msg.protocols.LispMapRequest.RequestBuilder) InfoRequestBuilder(org.onosproject.lisp.msg.protocols.LispInfoRequest.InfoRequestBuilder) DefaultInfoRequestBuilder(org.onosproject.lisp.msg.protocols.DefaultLispInfoRequest.DefaultInfoRequestBuilder) UnknownHostException(java.net.UnknownHostException) LispIpv4Address(org.onosproject.lisp.msg.types.LispIpv4Address) LispRouterFactory(org.onosproject.lisp.ctl.LispRouterFactory) DefaultRequestBuilder(org.onosproject.lisp.msg.protocols.DefaultLispMapRequest.DefaultRequestBuilder) LispAfiAddress(org.onosproject.lisp.msg.types.LispAfiAddress) LispMapRequest(org.onosproject.lisp.msg.protocols.LispMapRequest)

Example 4 with LispIpv4Address

use of org.onosproject.lisp.msg.types.LispIpv4Address in project onos by opennetworkinglab.

the class LispMappingDatabaseTest method test12MaskRange.

@Test
public void test12MaskRange() {
    byte cidr32 = (byte) 32;
    LispIpv4Address eid = new LispIpv4Address(IpAddress.valueOf(EID_IP_PREFIX_1_32));
    LispEidRecord record32 = new LispEidRecord(cidr32, eid);
    LispMapRecord mapRecordExpireMap32 = expireMapDb.getMapRecordByEidRecord(record32, true);
    LispMapRecord mapRecordRadixTree32 = radixTreeDb.getMapRecordByEidRecord(record32, true);
    byte cidr24 = (byte) 24;
    LispIpv4Address eid24 = new LispIpv4Address(IpAddress.valueOf(EID_IP_PREFIX_1_24));
    LispEidRecord record24 = new LispEidRecord(cidr24, eid24);
    LispMapRecord mapRecordExpireMap24 = expireMapDb.getMapRecordByEidRecord(record24, true);
    LispMapRecord mapRecordRadixTree24 = radixTreeDb.getMapRecordByEidRecord(record32, true);
    byte cidr16 = (byte) 16;
    LispIpv4Address eid16 = new LispIpv4Address(IpAddress.valueOf(EID_IP_PREFIX_1_16));
    LispEidRecord record16 = new LispEidRecord(cidr16, eid16);
    LispMapRecord mapRecordExpireMap16 = expireMapDb.getMapRecordByEidRecord(record16, true);
    LispMapRecord mapRecordRadixTree16 = radixTreeDb.getMapRecordByEidRecord(record16, true);
    byte cidr12 = (byte) 12;
    LispIpv4Address eid12 = new LispIpv4Address(IpAddress.valueOf(EID_IP_PREFIX_1_12));
    LispEidRecord record12 = new LispEidRecord(cidr12, eid12);
    LispMapRecord mapRecordExpireMap12 = expireMapDb.getMapRecordByEidRecord(record12, true);
    LispMapRecord mapRecordRadixTree12 = radixTreeDb.getMapRecordByEidRecord(record12, true);
    assertThat("Failed to fetch the RLOCs with /32 EID record", mapRecordExpireMap32.getLocatorCount(), is(2));
    assertThat("Failed to fetch the RLOCs with /24 EID record", mapRecordExpireMap24.getLocatorCount(), is(2));
    assertThat("Failed to fetch the RLOCs with /16 EID record", mapRecordExpireMap16.getLocatorCount(), is(2));
    assertThat("Failed to fetch the RLOCs with /12 EID record", mapRecordExpireMap12.getLocatorCount(), is(1));
    assertThat("Failed to fetch the RLOCs with /32 EID record", mapRecordRadixTree32.getLocatorCount(), is(2));
    assertThat("Failed to fetch the RLOCs with /24 EID record", mapRecordRadixTree24.getLocatorCount(), is(2));
    assertThat("Failed to fetch the RLOCs with /16 EID record", mapRecordRadixTree16.getLocatorCount(), is(2));
    assertThat("Failed to fetch the RLOCs with /12 EID record", mapRecordRadixTree12.getLocatorCount(), is(1));
    LispIpv4Address wrongEid = new LispIpv4Address(IpAddress.valueOf(EID_IP_PREFIX_3_24));
    LispEidRecord wrongRecord = new LispEidRecord(cidr24, wrongEid);
    LispMapRecord nullRecord = expireMapDb.getMapRecordByEidRecord(wrongRecord, true);
    assertNull("The record should be null", nullRecord);
}
Also used : LispIpv4Address(org.onosproject.lisp.msg.types.LispIpv4Address) LispMapRecord(org.onosproject.lisp.msg.protocols.LispMapRecord) LispEidRecord(org.onosproject.lisp.msg.protocols.LispEidRecord) Test(org.junit.Test)

Example 5 with LispIpv4Address

use of org.onosproject.lisp.msg.types.LispIpv4Address in project onos by opennetworkinglab.

the class DefaultLispEncapsulatedControlTest method getMapRecord.

private LispMapRecord getMapRecord() {
    MapRecordBuilder builder1 = new DefaultMapRecordBuilder();
    LispIpv4Address ipv4Locator1 = new LispIpv4Address(IpAddress.valueOf(RECORD_EID));
    return builder1.withRecordTtl(100).withIsAuthoritative(true).withMapVersionNumber((short) 1).withMaskLength((byte) 0x01).withAction(LispMapReplyAction.NativelyForward).withEidPrefixAfi(ipv4Locator1).build();
}
Also used : MapRecordBuilder(org.onosproject.lisp.msg.protocols.LispMapRecord.MapRecordBuilder) DefaultMapRecordBuilder(org.onosproject.lisp.msg.protocols.DefaultLispMapRecord.DefaultMapRecordBuilder) LispIpv4Address(org.onosproject.lisp.msg.types.LispIpv4Address) DefaultMapRecordBuilder(org.onosproject.lisp.msg.protocols.DefaultLispMapRecord.DefaultMapRecordBuilder)

Aggregations

LispIpv4Address (org.onosproject.lisp.msg.types.LispIpv4Address)49 Test (org.junit.Test)19 Before (org.junit.Before)18 LispAfiAddress (org.onosproject.lisp.msg.types.LispAfiAddress)10 DefaultMapRecordBuilder (org.onosproject.lisp.msg.protocols.DefaultLispMapRecord.DefaultMapRecordBuilder)8 MapRecordBuilder (org.onosproject.lisp.msg.protocols.LispMapRecord.MapRecordBuilder)8 LispIpv6Address (org.onosproject.lisp.msg.types.LispIpv6Address)6 LispEidRecord (org.onosproject.lisp.msg.protocols.LispEidRecord)4 LispMapRecord (org.onosproject.lisp.msg.protocols.LispMapRecord)4 NatAddressBuilder (org.onosproject.lisp.msg.types.lcaf.LispNatLcafAddress.NatAddressBuilder)4 IpAddress (org.onlab.packet.IpAddress)3 DefaultLocatorBuilder (org.onosproject.lisp.msg.protocols.DefaultLispLocator.DefaultLocatorBuilder)3 UnknownHostException (java.net.UnknownHostException)2 IpPrefix (org.onlab.packet.IpPrefix)2 DefaultInfoReplyBuilder (org.onosproject.lisp.msg.protocols.DefaultLispInfoReply.DefaultInfoReplyBuilder)2 DefaultInfoRequestBuilder (org.onosproject.lisp.msg.protocols.DefaultLispInfoRequest.DefaultInfoRequestBuilder)2 DefaultRequestBuilder (org.onosproject.lisp.msg.protocols.DefaultLispMapRequest.DefaultRequestBuilder)2 DefaultReferralRecordBuilder (org.onosproject.lisp.msg.protocols.DefaultLispReferralRecord.DefaultReferralRecordBuilder)2 InfoReplyBuilder (org.onosproject.lisp.msg.protocols.LispInfoReply.InfoReplyBuilder)2 InfoRequestBuilder (org.onosproject.lisp.msg.protocols.LispInfoRequest.InfoRequestBuilder)2