blob: 6017571b52ad8a65acc356732ebebf3e0329ba11 [file] [log] [blame]
Andrea Campanella7e6200a2016-03-21 09:48:40 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Andrea Campanella7e6200a2016-03-21 09:48:40 -07003 *
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 */
16
17package org.onosproject.netconf.ctl;
18
19import org.onlab.packet.IpAddress;
20import org.onosproject.net.key.DeviceKey;
21import org.onosproject.net.key.DeviceKeyId;
22import org.onosproject.net.key.DeviceKeyListener;
23import org.onosproject.net.key.DeviceKeyService;
24import org.onosproject.netconf.NetconfDeviceInfo;
25
26import java.util.Collection;
27
28/**
29 * Mock DeviceKey service to return device keys.
30 */
31class NetconfDeviceKeyServiceMock implements DeviceKeyService {
32
33 private static final String DEVICE_1_IP = "10.10.10.11";
34 private static final String DEVICE_2_IP = "10.10.10.12";
35 private static final String BAD_DEVICE_IP = "10.10.10.13";
36 private static final String DEVICE_IPV6 = "2001:db8::1";
37
38 private static final int DEVICE_1_PORT = 11;
39 private static final int DEVICE_2_PORT = 12;
40 private static final int BAD_DEVICE_PORT = 13;
41 private static final int IPV6_DEVICE_PORT = 14;
42
43 //DeviceInfo
44 private NetconfDeviceInfo deviceInfo1 =
45 new NetconfDeviceInfo("device1", "001", IpAddress.valueOf(DEVICE_1_IP),
46 DEVICE_1_PORT);
47 private NetconfDeviceInfo deviceInfo2 =
48 new NetconfDeviceInfo("device2", "002", IpAddress.valueOf(DEVICE_2_IP),
49 DEVICE_2_PORT);
50 private NetconfDeviceInfo badDeviceInfo3 =
51 new NetconfDeviceInfo("device3", "003", IpAddress.valueOf(BAD_DEVICE_IP),
52 BAD_DEVICE_PORT);
53 private NetconfDeviceInfo deviceInfoIpV6 =
54 new NetconfDeviceInfo("deviceIpv6", "004", IpAddress.valueOf(DEVICE_IPV6), IPV6_DEVICE_PORT);
55
56 @Override
57 public Collection<DeviceKey> getDeviceKeys() {
58 return null;
59 }
60
61 @Override
62 public DeviceKey getDeviceKey(DeviceKeyId deviceKeyId) {
63 if (deviceKeyId.toString().equals(deviceInfo1.getDeviceId().toString())) {
64 return DeviceKey.createDeviceKeyUsingUsernamePassword(
65 DeviceKeyId.deviceKeyId(deviceInfo1.getDeviceId().toString()),
66 null, deviceInfo1.name(), deviceInfo1.password());
67 } else if (deviceKeyId.toString().equals(deviceInfo2.getDeviceId().toString())) {
68 return DeviceKey.createDeviceKeyUsingUsernamePassword(
69 DeviceKeyId.deviceKeyId(deviceInfo2.getDeviceId().toString()),
70 null, deviceInfo2.name(), deviceInfo2.password());
71 } else if (deviceKeyId.toString().equals(badDeviceInfo3.getDeviceId().toString())) {
72 return DeviceKey.createDeviceKeyUsingUsernamePassword(
73 DeviceKeyId.deviceKeyId(badDeviceInfo3.getDeviceId().toString()),
74 null, badDeviceInfo3.name(), badDeviceInfo3.password());
75 } else if (deviceKeyId.toString().equals(deviceInfoIpV6.getDeviceId().toString())) {
76 return DeviceKey.createDeviceKeyUsingUsernamePassword(
77 DeviceKeyId.deviceKeyId(deviceInfoIpV6.getDeviceId().toString()),
78 null, deviceInfoIpV6.name(), deviceInfoIpV6.password());
79 }
80 return null;
81 }
82
83 @Override
84 public void addListener(DeviceKeyListener listener) {
85
86 }
87
88 @Override
89 public void removeListener(DeviceKeyListener listener) {
90
91 }
92}