xueliang | 37a396a | 2016-09-09 14:43:49 +0900 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.drivers.fujitsu; |
| 18 | |
| 19 | import org.onosproject.net.DeviceId; |
| 20 | import org.onosproject.net.driver.Behaviour; |
| 21 | import org.onosproject.net.driver.DefaultDriverHandler; |
| 22 | import org.onosproject.net.driver.DriverData; |
| 23 | import org.onosproject.mastership.MastershipService; |
| 24 | import org.onosproject.mastership.MastershipServiceAdapter; |
| 25 | import org.onosproject.netconf.NetconfController; |
| 26 | |
| 27 | |
| 28 | /** |
| 29 | * Mock DefaultDriverHandler. |
| 30 | */ |
| 31 | public class FujitsuDriverHandlerAdapter extends DefaultDriverHandler { |
| 32 | |
| 33 | private NetconfController controller; |
Satoshi Fujii | f108dd5 | 2016-10-14 10:35:22 -0700 | [diff] [blame] | 34 | private final MastershipService mastershipService = new InternalMastershipServiceMock(); |
xueliang | 37a396a | 2016-09-09 14:43:49 +0900 | [diff] [blame] | 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 | } |