blob: 1694d2aab4554eb4d0f50d094b4e4a81b28c2c80 [file] [log] [blame]
Hesam Rahimi4a409b42016-08-12 18:37:33 -04001/*
2 * Copyright 2016-present 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 */
16
17package org.onosproject.protocol.http;
18
19import org.onlab.packet.IpAddress;
20import org.onosproject.net.DeviceId;
21import org.onosproject.protocol.rest.RestSBDevice;
22
23import java.io.InputStream;
24import java.util.Map;
25
26/**
27 * Abstraction of an HTTP controller. Serves as a one stop shop for obtaining
28 * HTTP southbound devices and (un)register listeners.
29 */
30public interface HttpSBController {
31
32 /**
33 * Returns all the devices known to this controller.
34 *
35 * @return map of devices
36 */
37 Map<DeviceId, RestSBDevice> getDevices();
38
39 /**
40 * Returns a device by node identifier.
41 *
42 * @param deviceInfo node identifier
43 * @return RestSBDevice rest device
44 */
45 RestSBDevice getDevice(DeviceId deviceInfo);
46
47 /**
48 * Returns a device by Ip and Port.
49 *
50 * @param ip device ip
51 * @param port device port
52 * @return RestSBDevice rest device
53 */
54 RestSBDevice getDevice(IpAddress ip, int port);
55
56 /**
57 * Adds a device to the device map.
58 *
59 * @param device to be added
60 */
61 void addDevice(RestSBDevice device);
62
63 /**
64 * Removes the device from the devices map.
65 *
66 * @param deviceId to be removed
67 */
68 void removeDevice(DeviceId deviceId);
69
70 /**
71 * Does a HTTP POST request with specified parameters to the device.
72 *
73 * @param device device to make the request to
74 * @param request url of the request
75 * @param payload payload of the request as an InputStream
76 * @param mediaType type of content in the payload i.e. application/json
77 * @return true if operation returned 200, 201, 202, false otherwise
78 */
79 boolean post(DeviceId device, String request, InputStream payload, String mediaType);
80
81 /**
82 * Does a HTTP POST request with specified parameters to the device.
83 *
84 * @param <T> post return type
85 * @param device device to make the request to
86 * @param request url of the request
87 * @param payload payload of the request as an InputStream
88 * @param mediaType type of content in the payload i.e. application/json
89 * @param responseClass the type of response object we are interested in,
90 * such as String, InputStream.
91 * @return Object of type requested via responseClass.
92 */
93 <T> T post(DeviceId device, String request, InputStream payload,
94 String mediaType, Class<T> responseClass);
95
96 /**
97 * Does a HTTP PUT request with specified parameters to the device.
98 *
99 * @param device device to make the request to
100 * @param request resource path of the request
101 * @param payload payload of the request as an InputStream
102 * @param mediaType type of content in the payload i.e. application/json
103 * @return true if operation returned 200, 201, 202, false otherwise
104 */
105 boolean put(DeviceId device, String request, InputStream payload, String mediaType);
106
107 /**
108 * Does a HTTP GET request with specified parameters to the device.
109 *
110 * @param device device to make the request to
111 * @param request url of the request
112 * @param mediaType format to retrieve the content in
113 * @return an inputstream of data from the reply.
114 */
115 InputStream get(DeviceId device, String request, String mediaType);
116
117 /**
118 * Does a HTTP PATCH request with specified parameters to the device.
119 *
120 * @param device device to make the request to
121 * @param request url of the request
122 * @param payload payload of the request as an InputStream
123 * @param mediaType format to retrieve the content in
124 * @return true if operation returned 200, 201, 202, false otherwise
125 */
126 boolean patch(DeviceId device, String request, InputStream payload, String mediaType);
127
128 /**
129 * Does a HTTP DELETE request with specified parameters to the device.
130 *
131 * @param device device to make the request to
132 * @param request url of the request
133 * @param payload payload of the request as an InputStream
134 * @param mediaType type of content in the payload i.e. application/json
135 * @return true if operation returned 200 false otherwise
136 */
137 boolean delete(DeviceId device, String request, InputStream payload, String mediaType);
138
139}