blob: 6d7aad3d40dabc35b67223b5bf11793d017c9dcd [file] [log] [blame]
xueliang37a396a2016-09-09 14:43:49 +09001/*
2 * Copyright 2016-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
17package org.onosproject.drivers.fujitsu;
18
19import org.onosproject.net.DeviceId;
20import org.onosproject.net.driver.Behaviour;
21import org.onosproject.net.driver.DefaultDriverHandler;
22import org.onosproject.net.driver.DriverData;
23import org.onosproject.mastership.MastershipService;
24import org.onosproject.mastership.MastershipServiceAdapter;
25import org.onosproject.netconf.NetconfController;
26
27
28/**
29 * Mock DefaultDriverHandler.
30 */
31public class FujitsuDriverHandlerAdapter extends DefaultDriverHandler {
32
33 private NetconfController controller;
34 private final MastershipService mastershipService = new InternalMastershipServiceMock();;
35
36 /**
37 * Creates new driver handler with the attached driver data.
38 *
39 * @param data driver data to attach
40 */
41 public FujitsuDriverHandlerAdapter(DriverData data) {
42 super(data);
43 }
44
45 @Override
46 public boolean hasBehaviour(Class<? extends Behaviour> behaviourClass) {
47 return true;
48 }
49
50 @Override
51 public <T> T get(Class<T> serviceClass) {
52 if (serviceClass == NetconfController.class) {
53 return (T) this.controller;
54 } else if (serviceClass == MastershipService.class) {
55 return (T) this.mastershipService;
56 }
57 return null;
58 }
59
60 /**
61 * Set up initial environment.
62 *
63 * @param controller NETCONF controller instance
64 */
65 public void setUp(NetconfController controller) {
66 this.controller = controller;
67 }
68
69 /**
70 * Mock MastershipServiceAdapter.
71 */
72 private class InternalMastershipServiceMock extends MastershipServiceAdapter {
73
74 @Override
75 public boolean isLocalMaster(DeviceId deviceId) {
76 return true;
77 }
78 }
79
80}