blob: 4dc3c1afa77d9d761052de24a9d86054ef254a7f [file] [log] [blame]
Carmelo Cascone37d5dbf2016-04-18 15:15:48 -07001/*
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.bmv2.api.runtime;
18
Carmelo Casconef8cf2882016-05-04 14:06:17 -070019import org.apache.commons.lang3.tuple.Pair;
Carmelo Casconee4da9092016-04-26 12:14:08 -070020import org.onlab.util.ImmutableByteSequence;
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070021import org.onosproject.net.DeviceId;
Carmelo Casconee4da9092016-04-26 12:14:08 -070022
Carmelo Cascone37d5dbf2016-04-18 15:15:48 -070023import java.util.Collection;
Carmelo Cascone25f18882016-06-14 19:16:50 -070024import java.util.List;
Carmelo Cascone37d5dbf2016-04-18 15:15:48 -070025
26/**
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070027 * An agent to control a BMv2 device.
Carmelo Cascone37d5dbf2016-04-18 15:15:48 -070028 */
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070029public interface Bmv2DeviceAgent {
30
31 /**
32 * Returns the device ID of this agent.
33 *
34 * @return a device id
35 */
36 DeviceId deviceId();
37
38 /**
39 * Pings the device, returns true if the device is reachable, false otherwise.
40 *
41 * @return true if reachable, false otherwise
42 */
43 boolean ping();
44
Carmelo Cascone37d5dbf2016-04-18 15:15:48 -070045 /**
46 * Adds a new table entry.
47 *
48 * @param entry a table entry value
49 * @return table-specific entry ID
50 * @throws Bmv2RuntimeException if any error occurs
51 */
52 long addTableEntry(Bmv2TableEntry entry) throws Bmv2RuntimeException;
53
54 /**
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070055 * Modifies an existing table entry by updating its action.
Carmelo Cascone37d5dbf2016-04-18 15:15:48 -070056 *
57 * @param tableName string value of table name
58 * @param entryId long value of entry ID
59 * @param action an action value
60 * @throws Bmv2RuntimeException if any error occurs
61 */
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070062 void modifyTableEntry(String tableName, long entryId, Bmv2Action action) throws Bmv2RuntimeException;
Carmelo Cascone37d5dbf2016-04-18 15:15:48 -070063
64 /**
65 * Deletes currently installed entry.
66 *
67 * @param tableName string value of table name
68 * @param entryId long value of entry ID
69 * @throws Bmv2RuntimeException if any error occurs
70 */
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070071 void deleteTableEntry(String tableName, long entryId) throws Bmv2RuntimeException;
Carmelo Cascone37d5dbf2016-04-18 15:15:48 -070072
73 /**
74 * Sets table default action.
75 *
76 * @param tableName string value of table name
77 * @param action an action value
78 * @throws Bmv2RuntimeException if any error occurs
79 */
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070080 void setTableDefaultAction(String tableName, Bmv2Action action) throws Bmv2RuntimeException;
Carmelo Cascone37d5dbf2016-04-18 15:15:48 -070081
82 /**
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070083 * Returns information on the ports currently configured in the switch.
Carmelo Cascone37d5dbf2016-04-18 15:15:48 -070084 *
85 * @return collection of port information
86 * @throws Bmv2RuntimeException if any error occurs
87 */
88 Collection<Bmv2PortInfo> getPortsInfo() throws Bmv2RuntimeException;
89
90 /**
Carmelo Cascone25f18882016-06-14 19:16:50 -070091 * Returns a list of table entries installed in the given table.
Carmelo Cascone37d5dbf2016-04-18 15:15:48 -070092 *
Carmelo Cascone25f18882016-06-14 19:16:50 -070093 * @param tableName a string value
94 * @return a list of parsed table entries
Carmelo Cascone37d5dbf2016-04-18 15:15:48 -070095 * @throws Bmv2RuntimeException if any error occurs
96 */
Carmelo Cascone25f18882016-06-14 19:16:50 -070097 List<Bmv2ParsedTableEntry> getTableEntries(String tableName) throws Bmv2RuntimeException;
Carmelo Cascone37d5dbf2016-04-18 15:15:48 -070098
99 /**
Carmelo Casconee4da9092016-04-26 12:14:08 -0700100 * Requests the device to transmit a given byte sequence over the given port.
101 *
102 * @param portNumber a port number
103 * @param packet a byte sequence
104 * @throws Bmv2RuntimeException
105 */
106 void transmitPacket(int portNumber, ImmutableByteSequence packet) throws Bmv2RuntimeException;
107
108 /**
Carmelo Cascone17fc9e42016-05-31 11:29:21 -0700109 * Resets the state of the switch (e.g. delete all entries, etc.).
Carmelo Cascone37d5dbf2016-04-18 15:15:48 -0700110 *
111 * @throws Bmv2RuntimeException if any error occurs
112 */
113 void resetState() throws Bmv2RuntimeException;
Carmelo Casconeb57a1342016-05-03 09:43:06 -0700114
115 /**
Carmelo Cascone17fc9e42016-05-31 11:29:21 -0700116 * Returns the JSON configuration currently used to process packets.
Carmelo Casconeb57a1342016-05-03 09:43:06 -0700117 *
118 * @return a JSON-formatted string value
119 * @throws Bmv2RuntimeException if any error occurs
120 */
121 String dumpJsonConfig() throws Bmv2RuntimeException;
122
123 /**
Carmelo Cascone17fc9e42016-05-31 11:29:21 -0700124 * Returns the md5 sum of the JSON-formatted model configuration currently used to process packets.
Carmelo Casconeb57a1342016-05-03 09:43:06 -0700125 *
126 * @return a string value
127 * @throws Bmv2RuntimeException if any error occurs
128 */
129 String getJsonConfigMd5() throws Bmv2RuntimeException;
Carmelo Casconef8cf2882016-05-04 14:06:17 -0700130
131 /**
132 * Returns the counter values for a given table and entry.
133 *
134 * @param tableName a table name
135 * @param entryId an entry id
136 * @return a pair of long values, where the left value is the number of bytes and the right the number of packets
137 * @throws Bmv2RuntimeException if any error occurs
138 */
139 Pair<Long, Long> readTableEntryCounter(String tableName, long entryId) throws Bmv2RuntimeException;
Carmelo Cascone17fc9e42016-05-31 11:29:21 -0700140
141 /**
142 * Returns the counter values for a given counter and index.
143 *
144 * @param counterName a counter name
145 * @param index an integer value
146 * @return a pair of long values, where the left value is the number of bytes and the right value is the number of
147 * packets
148 * @throws Bmv2RuntimeException if any error occurs
149 */
150 Pair<Long, Long> readCounter(String counterName, int index) throws Bmv2RuntimeException;
151
152 /**
153 * Returns the ID of the current BMv2 process instance (used to distinguish between different executions of the
154 * same BMv2 device).
155 *
156 * @return an integer value
157 * @throws Bmv2RuntimeException if any error occurs
158 */
159 int getProcessInstanceId() throws Bmv2RuntimeException;
160
161 /**
162 * Uploads a new JSON configuration on the device.
163 *
164 * @param jsonString a string value
165 * @throws Bmv2RuntimeException if any error occurs
166 */
Carmelo Casconec18e82c2016-06-16 14:22:36 -0700167 void uploadNewJsonConfig(String jsonString) throws Bmv2RuntimeException;
Carmelo Cascone17fc9e42016-05-31 11:29:21 -0700168
169 /**
170 * Triggers a configuration swap on the device.
171 *
172 * @throws Bmv2RuntimeException
173 */
174 void swapJsonConfig() throws Bmv2RuntimeException;
Carmelo Cascone37d5dbf2016-04-18 15:15:48 -0700175}