blob: a78be6d625873812a73b61b327241d8d532e1f37 [file] [log] [blame]
Sean Condonfae8e662016-12-15 10:25:13 +00001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Sean Condonfae8e662016-12-15 10:25:13 +00003 *
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.drivers.netconf;
17
18import java.util.HashMap;
19import java.util.Map;
20import java.util.Set;
21
22import org.onlab.packet.Ip4Address;
23import org.onlab.packet.IpAddress;
24import org.onosproject.net.DeviceId;
25import org.onosproject.netconf.NetconfController;
26import org.onosproject.netconf.NetconfDevice;
27import org.onosproject.netconf.NetconfDeviceInfo;
28import org.onosproject.netconf.NetconfDeviceListener;
29import org.onosproject.netconf.NetconfException;
30
31public class MockNetconfController implements NetconfController {
32
33 private Map<DeviceId, NetconfDevice> devicesMap;
34
35 public MockNetconfController() {
36 devicesMap = new HashMap<DeviceId, NetconfDevice>();
37 }
38
39 @Override
40 public void addDeviceListener(NetconfDeviceListener listener) {
41 // TODO Auto-generated method stub
42
43 }
44
45 @Override
46 public void removeDeviceListener(NetconfDeviceListener listener) {
47 // TODO Auto-generated method stub
48
49 }
50
51 @Override
52 public NetconfDevice connectDevice(DeviceId deviceId) throws NetconfException {
53 NetconfDevice mockNetconfDevice = null;
54
55 String[] nameParts = deviceId.uri().toASCIIString().split(":");
56 IpAddress ipAddress = Ip4Address.valueOf(nameParts[1]);
57 int port = Integer.parseInt(nameParts[2]);
58 NetconfDeviceInfo ncdi = new NetconfDeviceInfo("mock", "mock", ipAddress, port);
59 try {
60 mockNetconfDevice = (new MockNetconfDeviceFactory()).createNetconfDevice(ncdi);
61 devicesMap.put(deviceId, mockNetconfDevice);
62 } catch (NetconfException e) {
63 // TODO Auto-generated catch block
64 e.printStackTrace();
65 }
66
67 return mockNetconfDevice;
68 }
69
70 @Override
71 public void disconnectDevice(DeviceId deviceId, boolean remove) {
72 // TODO Auto-generated method stub
73
74 }
75
76 @Override
77 public void removeDevice(DeviceId deviceId) {
78 // TODO Auto-generated method stub
79
80 }
81
82 @Override
83 public Map<DeviceId, NetconfDevice> getDevicesMap() {
84 return devicesMap;
85 }
86
87 @Override
88 public Set<DeviceId> getNetconfDevices() {
89 return devicesMap.keySet();
90 }
91
92 @Override
93 public NetconfDevice getNetconfDevice(DeviceId deviceInfo) {
94 return devicesMap.get(deviceInfo);
95 }
96
97 @Override
98 public NetconfDevice getNetconfDevice(IpAddress ip, int port) {
99 // TODO Auto-generated method stub
100 return null;
101 }
102
103}