Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | */ |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 16 | package org.onosproject.net.config.basics; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 17 | |
| 18 | import org.onosproject.core.ApplicationId; |
Thomas Vachuska | 9fadbfc | 2015-07-23 10:56:02 -0700 | [diff] [blame] | 19 | import org.onosproject.core.CoreService; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 20 | import org.onosproject.net.ConnectPoint; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.HostId; |
| 23 | import org.onosproject.net.LinkKey; |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 24 | import org.onosproject.net.config.SubjectFactory; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 25 | |
| 26 | import static com.google.common.base.Preconditions.checkArgument; |
| 27 | |
| 28 | /** |
| 29 | * Set of subject factories for potential configuration subjects. |
| 30 | */ |
| 31 | public final class SubjectFactories { |
| 32 | |
| 33 | // Construction forbidden |
| 34 | private SubjectFactories() { |
| 35 | } |
| 36 | |
Thomas Vachuska | 9fadbfc | 2015-07-23 10:56:02 -0700 | [diff] [blame] | 37 | // Required for resolving application identifiers |
| 38 | private static CoreService coreService; |
| 39 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 40 | public static final SubjectFactory<ApplicationId> APP_SUBJECT_FACTORY = |
| 41 | new SubjectFactory<ApplicationId>(ApplicationId.class, "apps") { |
| 42 | @Override |
| 43 | public ApplicationId createSubject(String key) { |
Thomas Vachuska | 9fadbfc | 2015-07-23 10:56:02 -0700 | [diff] [blame] | 44 | return coreService.registerApplication(key); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 45 | } |
| 46 | }; |
| 47 | |
| 48 | public static final SubjectFactory<DeviceId> DEVICE_SUBJECT_FACTORY = |
| 49 | new SubjectFactory<DeviceId>(DeviceId.class, "devices") { |
| 50 | @Override |
| 51 | public DeviceId createSubject(String key) { |
| 52 | return DeviceId.deviceId(key); |
| 53 | } |
| 54 | }; |
| 55 | |
Jonathan Hart | 111b42b | 2015-07-14 13:28:05 -0700 | [diff] [blame] | 56 | public static final SubjectFactory<ConnectPoint> CONNECT_POINT_SUBJECT_FACTORY = |
| 57 | new SubjectFactory<ConnectPoint>(ConnectPoint.class, "ports") { |
| 58 | @Override |
| 59 | public ConnectPoint createSubject(String key) { |
| 60 | return ConnectPoint.deviceConnectPoint(key); |
| 61 | } |
| 62 | }; |
| 63 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 64 | public static final SubjectFactory<HostId> HOST_SUBJECT_FACTORY = |
| 65 | new SubjectFactory<HostId>(HostId.class, "hosts") { |
| 66 | @Override |
| 67 | public HostId createSubject(String key) { |
| 68 | return HostId.hostId(key); |
| 69 | } |
| 70 | }; |
| 71 | |
| 72 | public static final SubjectFactory<LinkKey> LINK_SUBJECT_FACTORY = |
| 73 | new SubjectFactory<LinkKey>(LinkKey.class, "links") { |
| 74 | @Override |
| 75 | public LinkKey createSubject(String key) { |
| 76 | String[] cps = key.split("-"); |
| 77 | checkArgument(cps.length == 2, "Incorrect link key format: %s", key); |
| 78 | return LinkKey.linkKey(ConnectPoint.deviceConnectPoint(cps[0]), |
| 79 | ConnectPoint.deviceConnectPoint(cps[1])); |
| 80 | } |
| 81 | }; |
| 82 | |
Thomas Vachuska | 9fadbfc | 2015-07-23 10:56:02 -0700 | [diff] [blame] | 83 | /** |
| 84 | * Provides reference to the core service, which is required for |
| 85 | * application subject factory. |
| 86 | * |
| 87 | * @param service core service reference |
| 88 | */ |
| 89 | public static void setCoreService(CoreService service) { |
| 90 | coreService = service; |
| 91 | } |
| 92 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 93 | } |