blob: 0ba94599203d1f9b675a250169103fdd3682bc63 [file] [log] [blame]
Thomas Vachuska96d55b12015-05-11 08:52:03 -07001/*
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 */
16package org.onosproject.incubator.net.config.basics;
17
18import org.onosproject.core.ApplicationId;
Thomas Vachuska9fadbfc2015-07-23 10:56:02 -070019import org.onosproject.core.CoreService;
Thomas Vachuska96d55b12015-05-11 08:52:03 -070020import org.onosproject.incubator.net.config.SubjectFactory;
Brian O'Connorce2d8b52015-07-29 16:24:13 -070021import org.onosproject.incubator.net.domain.IntentDomainId;
Thomas Vachuska96d55b12015-05-11 08:52:03 -070022import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.HostId;
25import org.onosproject.net.LinkKey;
26
27import static com.google.common.base.Preconditions.checkArgument;
28
29/**
30 * Set of subject factories for potential configuration subjects.
31 */
32public final class SubjectFactories {
33
34 // Construction forbidden
35 private SubjectFactories() {
36 }
37
Thomas Vachuska9fadbfc2015-07-23 10:56:02 -070038 // Required for resolving application identifiers
39 private static CoreService coreService;
40
Thomas Vachuska96d55b12015-05-11 08:52:03 -070041 public static final SubjectFactory<ApplicationId> APP_SUBJECT_FACTORY =
42 new SubjectFactory<ApplicationId>(ApplicationId.class, "apps") {
43 @Override
44 public ApplicationId createSubject(String key) {
Thomas Vachuska9fadbfc2015-07-23 10:56:02 -070045 return coreService.registerApplication(key);
Thomas Vachuska96d55b12015-05-11 08:52:03 -070046 }
47 };
48
49 public static final SubjectFactory<DeviceId> DEVICE_SUBJECT_FACTORY =
50 new SubjectFactory<DeviceId>(DeviceId.class, "devices") {
51 @Override
52 public DeviceId createSubject(String key) {
53 return DeviceId.deviceId(key);
54 }
55 };
56
Jonathan Hart111b42b2015-07-14 13:28:05 -070057 public static final SubjectFactory<ConnectPoint> CONNECT_POINT_SUBJECT_FACTORY =
58 new SubjectFactory<ConnectPoint>(ConnectPoint.class, "ports") {
59 @Override
60 public ConnectPoint createSubject(String key) {
61 return ConnectPoint.deviceConnectPoint(key);
62 }
63 };
64
Thomas Vachuska96d55b12015-05-11 08:52:03 -070065 public static final SubjectFactory<HostId> HOST_SUBJECT_FACTORY =
66 new SubjectFactory<HostId>(HostId.class, "hosts") {
67 @Override
68 public HostId createSubject(String key) {
69 return HostId.hostId(key);
70 }
71 };
72
73 public static final SubjectFactory<LinkKey> LINK_SUBJECT_FACTORY =
74 new SubjectFactory<LinkKey>(LinkKey.class, "links") {
75 @Override
76 public LinkKey createSubject(String key) {
77 String[] cps = key.split("-");
78 checkArgument(cps.length == 2, "Incorrect link key format: %s", key);
79 return LinkKey.linkKey(ConnectPoint.deviceConnectPoint(cps[0]),
80 ConnectPoint.deviceConnectPoint(cps[1]));
81 }
82 };
83
Brian O'Connorce2d8b52015-07-29 16:24:13 -070084 public static final SubjectFactory<IntentDomainId> INTENT_DOMAIN_SUBJECT_FACTORY =
85 new SubjectFactory<IntentDomainId>(IntentDomainId.class, "domains") {
86 @Override
87 public IntentDomainId createSubject(String key) {
88 return IntentDomainId.valueOf(key);
89 }
90 };
91
Thomas Vachuska9fadbfc2015-07-23 10:56:02 -070092 /**
93 * Provides reference to the core service, which is required for
94 * application subject factory.
95 *
96 * @param service core service reference
97 */
98 public static void setCoreService(CoreService service) {
99 coreService = service;
100 }
101
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700102}