blob: 903a9922e80cb1ed918718db6ce0eb1c63c2969f [file] [log] [blame]
Jian Li55648ed2017-05-01 02:20:55 +09001/*
2 * Copyright 2017-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.provider.lisp.mapping.util;
17
18import org.onosproject.lisp.msg.types.LispAfiAddress;
19import org.onosproject.mapping.DefaultMappingKey;
20import org.onosproject.mapping.MappingKey;
21import org.onosproject.mapping.addresses.MappingAddress;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.device.DeviceService;
24import org.slf4j.Logger;
25import org.slf4j.LoggerFactory;
26
27import static org.onosproject.provider.lisp.mapping.util.MappingAddressBuilder.getAddress;
28
29/**
30 * Mapping key builder class.
31 */
32public class MappingKeyBuilder {
33 private static final Logger log =
34 LoggerFactory.getLogger(MappingKeyBuilder.class);
35
36 private final LispAfiAddress address;
37
38 private final DeviceId deviceId;
39
40 private final DeviceService deviceService;
41
42
43 /**
44 * Default constructor for MappingKeyBuilder.
45 *
46 * @param deviceService device service
47 * @param deviceId device identifier
48 * @param afiAddress AFI address
49 */
50 public MappingKeyBuilder(DeviceService deviceService, DeviceId deviceId,
51 LispAfiAddress afiAddress) {
52 this.deviceId = deviceId;
53 this.address = afiAddress;
54 this.deviceService = deviceService;
55 }
56
57 /**
58 * Builds mapping key from a AFI address.
59 *
60 * @return mapping key
61 */
62 public MappingKey build() {
63 MappingAddress mappingAddress = getAddress(deviceService, deviceId, address);
64 return DefaultMappingKey.builder().withAddress(mappingAddress).build();
65 }
66}