blob: 257bd276c73b2e1c2b7d6a57afec046b1c343378 [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
53 public static final SubjectFactory<HostId> HOST_SUBJECT_FACTORY =
54 new SubjectFactory<HostId>(HostId.class, "hosts") {
55 @Override
56 public HostId createSubject(String key) {
57 return HostId.hostId(key);
58 }
59 };
60
61 public static final SubjectFactory<LinkKey> LINK_SUBJECT_FACTORY =
62 new SubjectFactory<LinkKey>(LinkKey.class, "links") {
63 @Override
64 public LinkKey createSubject(String key) {
65 String[] cps = key.split("-");
66 checkArgument(cps.length == 2, "Incorrect link key format: %s", key);
67 return LinkKey.linkKey(ConnectPoint.deviceConnectPoint(cps[0]),
68 ConnectPoint.deviceConnectPoint(cps[1]));
69 }
70 };
71
72}