Carmelo Cascone | 37d5dbf | 2016-04-18 15:15:48 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.bmv2.api.runtime; |
| 18 | |
Carmelo Cascone | f8cf288 | 2016-05-04 14:06:17 -0700 | [diff] [blame] | 19 | import org.apache.commons.lang3.tuple.Pair; |
Carmelo Cascone | e4da909 | 2016-04-26 12:14:08 -0700 | [diff] [blame] | 20 | import org.onlab.util.ImmutableByteSequence; |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 21 | import org.onosproject.net.DeviceId; |
Carmelo Cascone | e4da909 | 2016-04-26 12:14:08 -0700 | [diff] [blame] | 22 | |
Carmelo Cascone | 37d5dbf | 2016-04-18 15:15:48 -0700 | [diff] [blame] | 23 | import java.util.Collection; |
Carmelo Cascone | 25f1888 | 2016-06-14 19:16:50 -0700 | [diff] [blame] | 24 | import java.util.List; |
Carmelo Cascone | 37d5dbf | 2016-04-18 15:15:48 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 27 | * An agent to control a BMv2 device. |
Carmelo Cascone | 37d5dbf | 2016-04-18 15:15:48 -0700 | [diff] [blame] | 28 | */ |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 29 | public 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 Cascone | 37d5dbf | 2016-04-18 15:15:48 -0700 | [diff] [blame] | 45 | /** |
| 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 Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 55 | * Modifies an existing table entry by updating its action. |
Carmelo Cascone | 37d5dbf | 2016-04-18 15:15:48 -0700 | [diff] [blame] | 56 | * |
| 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 Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 62 | void modifyTableEntry(String tableName, long entryId, Bmv2Action action) throws Bmv2RuntimeException; |
Carmelo Cascone | 37d5dbf | 2016-04-18 15:15:48 -0700 | [diff] [blame] | 63 | |
| 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 Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 71 | void deleteTableEntry(String tableName, long entryId) throws Bmv2RuntimeException; |
Carmelo Cascone | 37d5dbf | 2016-04-18 15:15:48 -0700 | [diff] [blame] | 72 | |
| 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 Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 80 | void setTableDefaultAction(String tableName, Bmv2Action action) throws Bmv2RuntimeException; |
Carmelo Cascone | 37d5dbf | 2016-04-18 15:15:48 -0700 | [diff] [blame] | 81 | |
| 82 | /** |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 83 | * Returns information on the ports currently configured in the switch. |
Carmelo Cascone | 37d5dbf | 2016-04-18 15:15:48 -0700 | [diff] [blame] | 84 | * |
| 85 | * @return collection of port information |
| 86 | * @throws Bmv2RuntimeException if any error occurs |
| 87 | */ |
| 88 | Collection<Bmv2PortInfo> getPortsInfo() throws Bmv2RuntimeException; |
| 89 | |
| 90 | /** |
Carmelo Cascone | 25f1888 | 2016-06-14 19:16:50 -0700 | [diff] [blame] | 91 | * Returns a list of table entries installed in the given table. |
Carmelo Cascone | 37d5dbf | 2016-04-18 15:15:48 -0700 | [diff] [blame] | 92 | * |
Carmelo Cascone | 25f1888 | 2016-06-14 19:16:50 -0700 | [diff] [blame] | 93 | * @param tableName a string value |
| 94 | * @return a list of parsed table entries |
Carmelo Cascone | 37d5dbf | 2016-04-18 15:15:48 -0700 | [diff] [blame] | 95 | * @throws Bmv2RuntimeException if any error occurs |
| 96 | */ |
Carmelo Cascone | 25f1888 | 2016-06-14 19:16:50 -0700 | [diff] [blame] | 97 | List<Bmv2ParsedTableEntry> getTableEntries(String tableName) throws Bmv2RuntimeException; |
Carmelo Cascone | 37d5dbf | 2016-04-18 15:15:48 -0700 | [diff] [blame] | 98 | |
| 99 | /** |
Carmelo Cascone | e4da909 | 2016-04-26 12:14:08 -0700 | [diff] [blame] | 100 | * 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 Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 109 | * Resets the state of the switch (e.g. delete all entries, etc.). |
Carmelo Cascone | 37d5dbf | 2016-04-18 15:15:48 -0700 | [diff] [blame] | 110 | * |
| 111 | * @throws Bmv2RuntimeException if any error occurs |
| 112 | */ |
| 113 | void resetState() throws Bmv2RuntimeException; |
Carmelo Cascone | b57a134 | 2016-05-03 09:43:06 -0700 | [diff] [blame] | 114 | |
| 115 | /** |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 116 | * Returns the JSON configuration currently used to process packets. |
Carmelo Cascone | b57a134 | 2016-05-03 09:43:06 -0700 | [diff] [blame] | 117 | * |
| 118 | * @return a JSON-formatted string value |
| 119 | * @throws Bmv2RuntimeException if any error occurs |
| 120 | */ |
| 121 | String dumpJsonConfig() throws Bmv2RuntimeException; |
| 122 | |
| 123 | /** |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 124 | * Returns the md5 sum of the JSON-formatted model configuration currently used to process packets. |
Carmelo Cascone | b57a134 | 2016-05-03 09:43:06 -0700 | [diff] [blame] | 125 | * |
| 126 | * @return a string value |
| 127 | * @throws Bmv2RuntimeException if any error occurs |
| 128 | */ |
| 129 | String getJsonConfigMd5() throws Bmv2RuntimeException; |
Carmelo Cascone | f8cf288 | 2016-05-04 14:06:17 -0700 | [diff] [blame] | 130 | |
| 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 Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 140 | |
| 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 Cascone | c18e82c | 2016-06-16 14:22:36 -0700 | [diff] [blame^] | 167 | void uploadNewJsonConfig(String jsonString) throws Bmv2RuntimeException; |
Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 168 | |
| 169 | /** |
| 170 | * Triggers a configuration swap on the device. |
| 171 | * |
| 172 | * @throws Bmv2RuntimeException |
| 173 | */ |
| 174 | void swapJsonConfig() throws Bmv2RuntimeException; |
Carmelo Cascone | 37d5dbf | 2016-04-18 15:15:48 -0700 | [diff] [blame] | 175 | } |