blob: e0ff08e01b9497220de6163d78d458f88b994714 [file] [log] [blame]
Yuta HIGUCHI76767fa2017-03-10 14:51:30 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Yuta HIGUCHI76767fa2017-03-10 14:51:30 -08003 *
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.net.config.inject;
17
18import org.onosproject.net.DeviceId;
19import org.onosproject.net.config.BaseConfig;
20import com.fasterxml.jackson.databind.ObjectMapper;
21import com.google.common.annotations.Beta;
22
23//{
24// "devices" : {
25// "inject:10.49.54.31" : {
26// "basic" : {
27// "driver" : "polatis-config",
28// "hwVersion" : "1.0",
29// "swVersion" : "2.0",
30// "serial" : "R-3000"
31// },
32// "inject" : {
33// "ports" : "4"
34// }
35// }
36// }
37// }
38
39/**
40 * Config to inject a Device.
41 */
42@Beta
43public class DeviceInjectionConfig
44 extends BaseConfig<DeviceId> {
45
46 /**
47 * Configuration key for {@link DeviceInjectionConfig}.
48 */
49 public static final String CONFIG_KEY = "inject";
50
51 /**
52 * JSON key for ports. {@value #PORTS}.
53 * Expects a string representation of decimal integer.
54 */
55 private static final String PORTS = "ports";
56
57
58 @Override
59 public boolean isValid() {
60 return true;
61 }
62
63 public String ports() {
64 return get(PORTS, "0");
65 }
66
67 /**
68 * Create a {@link DeviceInjectionConfig}.
69 * <p>
70 * Note: created instance needs to be initialized by #init(..) before using.
71 */
72 public DeviceInjectionConfig() {
73 super();
74 }
75
76 /**
77 * Create a {@link DeviceInjectionConfig} for specified Device.
78 * <p>
79 * Note: created instance is not bound to NetworkConfigService,
80 * cannot use {@link #apply()}. Must be passed to the service
81 * using NetworkConfigService#applyConfig
82 *
83 * @param did DeviceId
84 */
85 public DeviceInjectionConfig(DeviceId did) {
86 ObjectMapper mapper = new ObjectMapper();
87 init(did, CONFIG_KEY, mapper.createObjectNode(), mapper, null);
88 }
89
90 @Override
91 public String toString() {
92 return "DeviceInjectionConfig";
93 }
94}