blob: fe548df711730e123817479f48420d3f21c5424a [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;
19import org.onosproject.incubator.net.config.SubjectFactory;
20import org.onosproject.net.ConnectPoint;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.HostId;
23import org.onosproject.net.LinkKey;
24
25import static com.google.common.base.Preconditions.checkArgument;
26
27/**
28 * Set of subject factories for potential configuration subjects.
29 */
30public final class SubjectFactories {
31
32 // Construction forbidden
33 private SubjectFactories() {
34 }
35
36 public static final SubjectFactory<ApplicationId> APP_SUBJECT_FACTORY =
37 new SubjectFactory<ApplicationId>(ApplicationId.class, "apps") {
38 @Override
39 public ApplicationId createSubject(String key) {
40 // FIXME: figure out how to safely create sanctioned app ids
41 return null;
42 }
43 };
44
45 public static final SubjectFactory<DeviceId> DEVICE_SUBJECT_FACTORY =
46 new SubjectFactory<DeviceId>(DeviceId.class, "devices") {
47 @Override
48 public DeviceId createSubject(String key) {
49 return DeviceId.deviceId(key);
50 }
51 };
52
Jonathan Hart111b42b2015-07-14 13:28:05 -070053 public static final SubjectFactory<ConnectPoint> CONNECT_POINT_SUBJECT_FACTORY =
54 new SubjectFactory<ConnectPoint>(ConnectPoint.class, "ports") {
55 @Override
56 public ConnectPoint createSubject(String key) {
57 return ConnectPoint.deviceConnectPoint(key);
58 }
59 };
60
Thomas Vachuska96d55b12015-05-11 08:52:03 -070061 public static final SubjectFactory<HostId> HOST_SUBJECT_FACTORY =
62 new SubjectFactory<HostId>(HostId.class, "hosts") {
63 @Override
64 public HostId createSubject(String key) {
65 return HostId.hostId(key);
66 }
67 };
68
69 public static final SubjectFactory<LinkKey> LINK_SUBJECT_FACTORY =
70 new SubjectFactory<LinkKey>(LinkKey.class, "links") {
71 @Override
72 public LinkKey createSubject(String key) {
73 String[] cps = key.split("-");
74 checkArgument(cps.length == 2, "Incorrect link key format: %s", key);
75 return LinkKey.linkKey(ConnectPoint.deviceConnectPoint(cps[0]),
76 ConnectPoint.deviceConnectPoint(cps[1]));
77 }
78 };
79
80}