blob: 3edbb326ce7afc7a564201ca5c5182659b83d499 [file] [log] [blame]
Jeff Groom34c28ce2018-04-26 19:42:18 -06001/*
2 * Copyright 2017-present Open Networking Foundation
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
17package org.onosproject.drivers.ciena.waveserverai.netconf;
18
19import org.onosproject.core.CoreService;
20
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.driver.Behaviour;
23import org.onosproject.net.driver.DefaultDriver;
24import org.onosproject.drivers.netconf.MockCoreService;
25import org.onosproject.drivers.netconf.MockNetconfController;
26import org.onosproject.drivers.netconf.MockNetconfDevice;
27import org.onosproject.net.driver.DefaultDriverData;
28import org.onosproject.net.driver.Driver;
29import org.onosproject.net.driver.DriverData;
30import org.onosproject.net.driver.DriverHandler;
31import org.onosproject.net.flow.FlowRuleProgrammable;
32import org.onosproject.netconf.NetconfController;
33import org.onosproject.netconf.NetconfException;
34
35import java.util.HashMap;
36import java.util.Map;
37
38
39/**
40 * A Mock implementation of the DriverHandler to facilitate unit tests.
41 *
42 * This brings in the implementations of
43 * MockCoreService, MockNetconfDevice and MockNetconfSessionWaveserverAi
44 */
45public class MockWaveserverAiDriverHandler implements DriverHandler {
46
47 private static final String CIENA_DRIVERS = "com.ciena.drivers";
48
49 private DriverData mockDriverData;
50
51 private NetconfController ncc;
52 private CoreService coreService;
53
54 public MockWaveserverAiDriverHandler() throws NetconfException {
55 Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours =
56 new HashMap<Class<? extends Behaviour>, Class<? extends Behaviour>>();
57 behaviours.put(FlowRuleProgrammable.class, FlowRuleProgrammable.class);
58
59 Map<String, String> properties = new HashMap<String, String>();
60
61 Driver mockDriver =
62 new DefaultDriver("mockDriver", null,
63 "ONOSProject", "1.0.0",
64 "1.0.0", behaviours, properties);
65 DeviceId mockDeviceId = DeviceId.deviceId("netconf:1.2.3.4:830");
66 mockDriverData = new DefaultDriverData(mockDriver, mockDeviceId);
67
68 ncc = new MockNetconfController();
69 MockNetconfDevice device = (MockNetconfDevice) ncc.connectDevice(mockDeviceId);
70 device.setNcSessionImpl(MockNetconfSessionWaveserverAi.class);
71
72 coreService = new MockCoreService();
73 coreService.registerApplication(CIENA_DRIVERS);
74 }
75
76 @Override
77 public Driver driver() {
78 return mockDriverData.driver();
79 }
80
81 @Override
82 public DriverData data() {
83 return mockDriverData;
84 }
85
86 @Override
87 public <T extends Behaviour> T behaviour(Class<T> behaviourClass) {
88 // TODO Auto-generated method stub
89 return null;
90 }
91
92 @Override
93 public <T> T get(Class<T> serviceClass) {
94 if (serviceClass.equals(NetconfController.class)) {
95 return (T) ncc;
96
97 } else if (serviceClass.equals(CoreService.class)) {
98 return (T) coreService;
99
100 }
101
102 return null;
103 }
104
105}