Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.drivers.netconf; |
| 17 | |
| 18 | import java.util.HashMap; |
| 19 | import java.util.Map; |
| 20 | import java.util.Set; |
| 21 | |
| 22 | import org.onlab.packet.Ip4Address; |
| 23 | import org.onlab.packet.IpAddress; |
| 24 | import org.onosproject.net.DeviceId; |
| 25 | import org.onosproject.netconf.NetconfController; |
| 26 | import org.onosproject.netconf.NetconfDevice; |
| 27 | import org.onosproject.netconf.NetconfDeviceInfo; |
| 28 | import org.onosproject.netconf.NetconfDeviceListener; |
| 29 | import org.onosproject.netconf.NetconfException; |
| 30 | |
| 31 | public 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 | } |