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 | |
David K. Bainbridge | 1a10d62 | 2018-05-07 12:32:27 -0700 | [diff] [blame] | 18 | import java.util.HashSet; |
| 19 | import java.util.Set; |
| 20 | |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 21 | import org.onosproject.core.ApplicationId; |
| 22 | import org.onosproject.core.CoreService; |
| 23 | import org.onosproject.core.DefaultApplicationId; |
| 24 | import org.onosproject.core.IdGenerator; |
| 25 | import org.onosproject.core.Version; |
| 26 | import org.onosproject.net.intent.MockIdGenerator; |
| 27 | |
| 28 | public class MockCoreService implements CoreService { |
| 29 | |
| 30 | private HashSet<ApplicationId> appIds; |
| 31 | private Version version; |
David K. Bainbridge | 1a10d62 | 2018-05-07 12:32:27 -0700 | [diff] [blame] | 32 | private int nextAppId = 101; |
| 33 | |
| 34 | public MockCoreService(int baseId, String... apps) { |
| 35 | nextAppId = baseId; |
| 36 | appIds = new HashSet<ApplicationId>(); |
| 37 | for (String app : apps) { |
| 38 | appIds.add(new DefaultApplicationId(nextAppId, app)); |
| 39 | nextAppId += 1; |
| 40 | } |
| 41 | version = Version.version(1, 1, "1", "1"); |
| 42 | } |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 43 | |
| 44 | public MockCoreService() { |
David K. Bainbridge | 1a10d62 | 2018-05-07 12:32:27 -0700 | [diff] [blame] | 45 | this(101, "org.onosproject.drivers.netconf"); |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 46 | appIds = new HashSet<ApplicationId>(); |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public Version version() { |
| 51 | return version; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public Set<ApplicationId> getAppIds() { |
| 56 | return appIds; |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public ApplicationId getAppId(Short id) { |
David K. Bainbridge | 1a10d62 | 2018-05-07 12:32:27 -0700 | [diff] [blame] | 61 | for (ApplicationId appId : appIds) { |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 62 | if (appId.id() == id.shortValue()) { |
| 63 | return appId; |
| 64 | } |
| 65 | } |
| 66 | return null; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public ApplicationId getAppId(String name) { |
David K. Bainbridge | 1a10d62 | 2018-05-07 12:32:27 -0700 | [diff] [blame] | 71 | for (ApplicationId appId : appIds) { |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 72 | if (appId.name().equalsIgnoreCase(name)) { |
| 73 | return appId; |
| 74 | } |
| 75 | } |
| 76 | return null; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public ApplicationId registerApplication(String name) { |
David K. Bainbridge | 1a10d62 | 2018-05-07 12:32:27 -0700 | [diff] [blame] | 81 | // Check if the app already exists |
| 82 | ApplicationId appId = getAppId(name); |
| 83 | if (appId == null) { |
| 84 | appId = new DefaultApplicationId(nextAppId, name); |
| 85 | nextAppId += 1; |
| 86 | appIds.add(appId); |
| 87 | } |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 88 | return appId; |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public ApplicationId registerApplication(String name, Runnable preDeactivate) { |
| 93 | // TODO Auto-generated method stub |
| 94 | return null; |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public IdGenerator getIdGenerator(String topic) { |
Thomas Vachuska | 2048c1f | 2017-05-10 19:32:22 -0700 | [diff] [blame] | 99 | return MockIdGenerator.INSTANCE; |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | } |