blob: 32121aec2f0e1a098f0329955450d03180a0cc9b [file] [log] [blame]
hirokifca084b2018-06-02 08:29:42 -07001/*
2 * Copyright 2018-present Open Networking Foundation
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 */
16
17package org.onosproject.odtn.internal;
18
19import org.onosproject.net.config.NetworkConfigService;
20import org.onosproject.odtn.config.TerminalDeviceConfig;
21import org.onosproject.odtn.utils.tapi.TapiNepRef;
22
23import org.slf4j.Logger;
24import org.slf4j.LoggerFactory;
25
26import static org.onlab.osgi.DefaultServiceDirectory.getService;
27
28public final class DeviceConfigEventEmitter {
29
30 private final Logger log = LoggerFactory.getLogger(getClass());
31
32 private NetworkConfigService netcfgService;
33
34 private DeviceConfigEventEmitter() {
35 }
36
37 public static DeviceConfigEventEmitter create() {
38 DeviceConfigEventEmitter self = new DeviceConfigEventEmitter();
39 self.netcfgService = getService(NetworkConfigService.class);
40 return self;
41 }
42
43 /**
44 * Emit NetworkConfig event with parameters for device config.
45 *
46 * @param line side NodeEdgePoint of connection
47 * @param client side NodeEdgePoint of connection
48 * @param enable or disable
49 */
50 public void emit(TapiNepRef line, TapiNepRef client, boolean enable) {
51
52 // FIXME Config class should be implemented as behaviour to support
53 // multi device types.
54 TerminalDeviceConfig cfg = TerminalDeviceConfig.create(line, client);
55 if (enable) {
56 cfg.enable();
57 } else {
58 cfg.disable();
59 }
60 netcfgService.applyConfig(line.getConnectPoint(), TerminalDeviceConfig.class, cfg.node());
61 }
62
63}