Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame^] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.drivers.netconf; |
| 17 | |
| 18 | import java.util.HashMap; |
| 19 | import java.util.Map; |
| 20 | |
| 21 | import org.onosproject.core.CoreService; |
| 22 | import org.onosproject.mastership.MastershipService; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.driver.Behaviour; |
| 25 | import org.onosproject.net.driver.DefaultDriver; |
| 26 | import org.onosproject.net.driver.DefaultDriverData; |
| 27 | import org.onosproject.net.driver.Driver; |
| 28 | import org.onosproject.net.driver.DriverData; |
| 29 | import org.onosproject.net.driver.DriverHandler; |
| 30 | import org.onosproject.net.flow.FlowRuleProgrammable; |
| 31 | import org.onosproject.netconf.NetconfController; |
| 32 | import org.onosproject.netconf.NetconfException; |
| 33 | |
| 34 | public class MockDriverHandler implements DriverHandler { |
| 35 | |
| 36 | private DriverData mockDriverData; |
| 37 | |
| 38 | private NetconfController ncc; |
| 39 | private CoreService coreService; |
| 40 | private MastershipService mastershipService; |
| 41 | |
| 42 | public MockDriverHandler() throws NetconfException { |
| 43 | Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = |
| 44 | new HashMap<Class<? extends Behaviour>, Class<? extends Behaviour>>(); |
| 45 | behaviours.put(FlowRuleProgrammable.class, FlowRuleProgrammable.class); |
| 46 | |
| 47 | Map<String, String> properties = new HashMap<String, String>(); |
| 48 | |
| 49 | Driver mockDriver = |
| 50 | new DefaultDriver("mockDriver", null, "ONOSProject", "1.0.0", "1.0.0", behaviours, properties); |
| 51 | DeviceId mockDeviceId = DeviceId.deviceId("netconf:1.2.3.4:830"); |
| 52 | mockDriverData = new DefaultDriverData(mockDriver, mockDeviceId); |
| 53 | |
| 54 | |
| 55 | ncc = new MockNetconfController(); |
| 56 | ncc.connectDevice(mockDeviceId); |
| 57 | |
| 58 | coreService = new MockCoreService(); |
| 59 | mastershipService = new MockMastershipService(); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public Driver driver() { |
| 64 | return mockDriverData.driver(); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public DriverData data() { |
| 69 | return mockDriverData; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public <T extends Behaviour> T behaviour(Class<T> behaviourClass) { |
| 74 | // TODO Auto-generated method stub |
| 75 | return null; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public <T> T get(Class<T> serviceClass) { |
| 80 | if (serviceClass.equals(NetconfController.class)) { |
| 81 | return (T) ncc; |
| 82 | |
| 83 | } else if (serviceClass.equals(CoreService.class)) { |
| 84 | return (T) coreService; |
| 85 | |
| 86 | } else if (serviceClass.equals(MastershipService.class)) { |
| 87 | return (T) mastershipService; |
| 88 | |
| 89 | } |
| 90 | |
| 91 | return null; |
| 92 | } |
| 93 | |
| 94 | } |