Mehmed Mustafa | 3e269df | 2017-11-24 17:19:49 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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 | |
| 17 | package org.onosproject.p4runtime.model; |
| 18 | |
| 19 | import com.google.common.collect.ImmutableList; |
| 20 | import com.google.common.collect.ImmutableMap; |
| 21 | import com.google.common.collect.ImmutableSet; |
| 22 | import com.google.common.testing.EqualsTester; |
| 23 | import org.junit.Test; |
| 24 | import org.onosproject.net.pi.model.PiActionId; |
| 25 | import org.onosproject.net.pi.model.PiActionModel; |
| 26 | import org.onosproject.net.pi.model.PiActionParamId; |
| 27 | import org.onosproject.net.pi.model.PiActionParamModel; |
| 28 | import org.onosproject.net.pi.model.PiActionProfileId; |
| 29 | import org.onosproject.net.pi.model.PiActionProfileModel; |
| 30 | import org.onosproject.net.pi.model.PiControlMetadataId; |
| 31 | import org.onosproject.net.pi.model.PiControlMetadataModel; |
| 32 | import org.onosproject.net.pi.model.PiCounterId; |
| 33 | import org.onosproject.net.pi.model.PiCounterModel; |
| 34 | import org.onosproject.net.pi.model.PiCounterType; |
| 35 | import org.onosproject.net.pi.model.PiMatchFieldId; |
| 36 | import org.onosproject.net.pi.model.PiMatchFieldModel; |
| 37 | import org.onosproject.net.pi.model.PiMatchType; |
| 38 | import org.onosproject.net.pi.model.PiMeterId; |
| 39 | import org.onosproject.net.pi.model.PiMeterModel; |
| 40 | import org.onosproject.net.pi.model.PiMeterType; |
| 41 | import org.onosproject.net.pi.model.PiPacketOperationModel; |
| 42 | import org.onosproject.net.pi.model.PiPacketOperationType; |
| 43 | import org.onosproject.net.pi.model.PiPipelineModel; |
FrankWang | 2674e45 | 2018-05-24 17:13:35 +0800 | [diff] [blame] | 44 | import org.onosproject.net.pi.model.PiRegisterId; |
| 45 | import org.onosproject.net.pi.model.PiRegisterModel; |
Mehmed Mustafa | 3e269df | 2017-11-24 17:19:49 +0300 | [diff] [blame] | 46 | import org.onosproject.net.pi.model.PiTableId; |
| 47 | import org.onosproject.net.pi.model.PiTableModel; |
| 48 | import org.onosproject.net.pi.model.PiTableType; |
| 49 | |
| 50 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 51 | |
| 52 | /** |
| 53 | * Unit tests for P4PipelineModel class. |
| 54 | */ |
| 55 | public class P4PipelineModelTest { |
| 56 | |
| 57 | /* Action Profiles */ |
| 58 | private static final PiActionProfileId PI_ACTION_PROFILE_ID_1 = PiActionProfileId.of("Action1"); |
| 59 | private static final PiActionProfileId PI_ACTION_PROFILE_ID_2 = PiActionProfileId.of("Action2"); |
| 60 | |
| 61 | private static final PiTableId ACTION_PI_TABLE_ID_1 = PiTableId.of("ActionTable1"); |
| 62 | private static final PiTableId ACTION_PI_TABLE_ID_2 = PiTableId.of("ActionTable2"); |
| 63 | |
| 64 | private static final ImmutableSet<PiTableId> ACTION_TABLES_1 = new ImmutableSet.Builder<PiTableId>() |
| 65 | .add(ACTION_PI_TABLE_ID_1) |
| 66 | .build(); |
| 67 | |
| 68 | private static final ImmutableSet<PiTableId> ACTION_TABLES_2 = new ImmutableSet.Builder<PiTableId>() |
| 69 | .add(ACTION_PI_TABLE_ID_2) |
| 70 | .build(); |
| 71 | |
| 72 | private static final boolean ACTION_HAS_SELECTOR_1 = true; |
| 73 | private static final boolean ACTION_HAS_SELECTOR_2 = false; |
| 74 | |
| 75 | private static final long ACTION_MAX_SIZE_1 = 100; |
| 76 | private static final long ACTION_MAX_SIZE_2 = 200; |
| 77 | |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 78 | private static final int ACTION_MAX_GROUP_SIZE_1 = 10; |
| 79 | private static final int ACTION_MAX_GROUP_SIZE_2 = 20; |
| 80 | |
Mehmed Mustafa | 3e269df | 2017-11-24 17:19:49 +0300 | [diff] [blame] | 81 | private static final PiActionProfileModel P4_ACTION_PROFILE_MODEL_1 = |
| 82 | new P4ActionProfileModel(PI_ACTION_PROFILE_ID_1, ACTION_TABLES_1, |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 83 | ACTION_HAS_SELECTOR_1, ACTION_MAX_SIZE_1, |
| 84 | ACTION_MAX_GROUP_SIZE_1); |
Mehmed Mustafa | 3e269df | 2017-11-24 17:19:49 +0300 | [diff] [blame] | 85 | private static final PiActionProfileModel P4_ACTION_PROFILE_MODEL_2 = |
| 86 | new P4ActionProfileModel(PI_ACTION_PROFILE_ID_2, ACTION_TABLES_2, |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 87 | ACTION_HAS_SELECTOR_2, ACTION_MAX_SIZE_2, |
| 88 | ACTION_MAX_GROUP_SIZE_2); |
Mehmed Mustafa | 3e269df | 2017-11-24 17:19:49 +0300 | [diff] [blame] | 89 | |
| 90 | /* Counters */ |
| 91 | private static final PiCounterId PI_COUNTER_ID_1 = PiCounterId.of("Counter1"); |
| 92 | private static final PiCounterId PI_COUNTER_ID_2 = PiCounterId.of("Counter2"); |
| 93 | |
| 94 | private static final PiCounterType PI_COUNTER_TYPE_1 = PiCounterType.DIRECT; |
| 95 | private static final PiCounterType PI_COUNTER_TYPE_2 = PiCounterType.INDIRECT; |
| 96 | |
| 97 | private static final PiCounterModel.Unit COUNTER_UNIT_BYTES = P4CounterModel.Unit.BYTES; |
| 98 | private static final PiCounterModel.Unit COUNTER_UNIT_PACKETS = P4CounterModel.Unit.PACKETS; |
| 99 | |
| 100 | private static final PiTableId COUNTER_PI_TABLE_ID_1 = PiTableId.of("CounterTable1"); |
| 101 | private static final PiTableId COUNTER_PI_TABLE_ID_2 = PiTableId.of("CounterTable2"); |
| 102 | |
| 103 | private static final long COUNTER_SIZE_1 = 1000; |
| 104 | private static final long COUNTER_SIZE_2 = 2000; |
| 105 | |
| 106 | private static final PiCounterModel P4_COUNTER_MODEL_1 = |
| 107 | new P4CounterModel(PI_COUNTER_ID_1, PI_COUNTER_TYPE_1, |
| 108 | COUNTER_UNIT_BYTES, COUNTER_PI_TABLE_ID_1, COUNTER_SIZE_1); |
| 109 | private static final PiCounterModel P4_COUNTER_MODEL_2 = |
| 110 | new P4CounterModel(PI_COUNTER_ID_2, PI_COUNTER_TYPE_2, |
| 111 | COUNTER_UNIT_PACKETS, COUNTER_PI_TABLE_ID_2, COUNTER_SIZE_2); |
| 112 | |
| 113 | private static final ImmutableMap<PiCounterId, PiCounterModel> COUNTERS_1 = |
| 114 | new ImmutableMap.Builder<PiCounterId, PiCounterModel>() |
| 115 | .put(PI_COUNTER_ID_1, P4_COUNTER_MODEL_1) |
| 116 | .build(); |
| 117 | private static final ImmutableMap<PiCounterId, PiCounterModel> COUNTERS_2 = |
| 118 | new ImmutableMap.Builder<PiCounterId, PiCounterModel>() |
| 119 | .put(PI_COUNTER_ID_2, P4_COUNTER_MODEL_2) |
| 120 | .build(); |
| 121 | |
| 122 | /* Meters */ |
| 123 | private static final PiMeterId PI_METER_ID_1 = PiMeterId.of("Meter1"); |
| 124 | private static final PiMeterId PI_METER_ID_2 = PiMeterId.of("Meter2"); |
| 125 | |
| 126 | private static final PiMeterType PI_METER_TYPE_1 = PiMeterType.DIRECT; |
| 127 | private static final PiMeterType PI_METER_TYPE_2 = PiMeterType.INDIRECT; |
| 128 | |
| 129 | private static final PiMeterModel.Unit METER_UNIT_BYTES = P4MeterModel.Unit.BYTES; |
| 130 | private static final PiMeterModel.Unit METER_UNIT_PACKETS = P4MeterModel.Unit.PACKETS; |
| 131 | |
| 132 | private static final PiTableId METER_PI_TABLE_ID_1 = PiTableId.of("MeterTable1"); |
| 133 | private static final PiTableId METER_PI_TABLE_ID_2 = PiTableId.of("MeterTable2"); |
| 134 | |
| 135 | private static final long METER_SIZE_1 = 1000; |
| 136 | private static final long METER_SIZE_2 = 2000; |
| 137 | |
| 138 | private static final PiMeterModel P4_METER_MODEL_1 = |
| 139 | new P4MeterModel(PI_METER_ID_1, PI_METER_TYPE_1, METER_UNIT_BYTES, METER_PI_TABLE_ID_1, METER_SIZE_1); |
| 140 | private static final PiMeterModel P4_METER_MODEL_2 = |
| 141 | new P4MeterModel(PI_METER_ID_2, PI_METER_TYPE_2, METER_UNIT_PACKETS, METER_PI_TABLE_ID_2, METER_SIZE_2); |
| 142 | |
| 143 | private static final ImmutableMap<PiMeterId, PiMeterModel> METERS_1 = |
| 144 | new ImmutableMap.Builder<PiMeterId, PiMeterModel>() |
| 145 | .put(PI_METER_ID_1, P4_METER_MODEL_1) |
| 146 | .build(); |
| 147 | private static final ImmutableMap<PiMeterId, PiMeterModel> METERS_2 = |
| 148 | new ImmutableMap.Builder<PiMeterId, PiMeterModel>() |
| 149 | .put(PI_METER_ID_2, P4_METER_MODEL_2) |
| 150 | .build(); |
| 151 | |
FrankWang | 2674e45 | 2018-05-24 17:13:35 +0800 | [diff] [blame] | 152 | /* Registers */ |
| 153 | private static final PiRegisterId PI_REGISTER_ID_1 = PiRegisterId.of("Register1"); |
| 154 | private static final PiRegisterId PI_REGISTER_ID_2 = PiRegisterId.of("Register2"); |
| 155 | |
| 156 | private static final long REGISTER_SIZE_1 = 1000; |
| 157 | private static final long REGISTER_SIZE_2 = 2000; |
| 158 | |
| 159 | private static final P4RegisterModel P4_REGISTER_MODEL_1 = new P4RegisterModel(PI_REGISTER_ID_1, REGISTER_SIZE_1); |
| 160 | private static final P4RegisterModel P4_REGISTER_MODEL_2 = new P4RegisterModel(PI_REGISTER_ID_2, REGISTER_SIZE_2); |
| 161 | |
| 162 | private static final ImmutableMap<PiRegisterId, PiRegisterModel> REGISTERS_1 = |
| 163 | new ImmutableMap.Builder<PiRegisterId, PiRegisterModel>() |
| 164 | .put(PI_REGISTER_ID_1, P4_REGISTER_MODEL_1) |
| 165 | .build(); |
| 166 | private static final ImmutableMap<PiRegisterId, PiRegisterModel> REGISTERS_2 = |
| 167 | new ImmutableMap.Builder<PiRegisterId, PiRegisterModel>() |
| 168 | .put(PI_REGISTER_ID_2, P4_REGISTER_MODEL_2) |
| 169 | .build(); |
| 170 | |
Mehmed Mustafa | 3e269df | 2017-11-24 17:19:49 +0300 | [diff] [blame] | 171 | /* Match Fields */ |
| 172 | private static final PiMatchFieldId PI_MATCH_FIELD_ID_1 = PiMatchFieldId.of("MatchField1"); |
| 173 | private static final PiMatchFieldId PI_MATCH_FIELD_ID_2 = PiMatchFieldId.of("MatchField2"); |
| 174 | |
| 175 | private static final int MATCH_FIELD_BIT_WIDTH_1 = 8; |
| 176 | private static final int MATCH_FIELD_BIT_WIDTH_2 = 16; |
| 177 | |
| 178 | private static final PiMatchType PI_MATCH_TYPE_1 = PiMatchType.EXACT; |
| 179 | private static final PiMatchType PI_MATCH_TYPE_2 = PiMatchType.TERNARY; |
| 180 | |
| 181 | private static final PiMatchFieldModel P4_MATCH_FIELD_MODEL_1 = |
| 182 | new P4MatchFieldModel(PI_MATCH_FIELD_ID_1, MATCH_FIELD_BIT_WIDTH_1, PI_MATCH_TYPE_1); |
| 183 | private static final PiMatchFieldModel P4_MATCH_FIELD_MODEL_2 = |
| 184 | new P4MatchFieldModel(PI_MATCH_FIELD_ID_2, MATCH_FIELD_BIT_WIDTH_2, PI_MATCH_TYPE_2); |
| 185 | |
| 186 | private static final ImmutableMap<PiMatchFieldId, PiMatchFieldModel> MATCH_FIELDS_1 = |
| 187 | new ImmutableMap.Builder<PiMatchFieldId, PiMatchFieldModel>() |
| 188 | .put(PI_MATCH_FIELD_ID_1, P4_MATCH_FIELD_MODEL_1) |
| 189 | .build(); |
| 190 | private static final ImmutableMap<PiMatchFieldId, PiMatchFieldModel> MATCH_FIELDS_2 = |
| 191 | new ImmutableMap.Builder<PiMatchFieldId, PiMatchFieldModel>() |
| 192 | .put(PI_MATCH_FIELD_ID_2, P4_MATCH_FIELD_MODEL_2) |
| 193 | .build(); |
| 194 | |
| 195 | /* Actions */ |
| 196 | private static final PiActionId PI_ACTION_ID_1 = PiActionId.of("Action1"); |
| 197 | private static final PiActionId PI_ACTION_ID_2 = PiActionId.of("Action2"); |
| 198 | |
| 199 | private static final PiActionParamId PI_ACTION_PARAM_ID_1 = PiActionParamId.of("ActionParameter1"); |
| 200 | private static final PiActionParamId PI_ACTION_PARAM_ID_2 = PiActionParamId.of("ActionParameter2"); |
| 201 | |
| 202 | private static final int ACTION_PARAM_BIT_WIDTH_1 = 8; |
| 203 | private static final int ACTION_PARAM_BIT_WIDTH_2 = 16; |
| 204 | |
| 205 | private static final PiActionParamModel P4_ACTION_PARAM_MODEL_1 = |
| 206 | new P4ActionParamModel(PI_ACTION_PARAM_ID_1, ACTION_PARAM_BIT_WIDTH_1); |
| 207 | private static final PiActionParamModel P4_ACTION_PARAM_MODEL_2 = |
| 208 | new P4ActionParamModel(PI_ACTION_PARAM_ID_2, ACTION_PARAM_BIT_WIDTH_2); |
| 209 | |
| 210 | private static final ImmutableMap<PiActionParamId, PiActionParamModel> PI_ACTION_PARAMS_1 = |
| 211 | new ImmutableMap.Builder<PiActionParamId, PiActionParamModel>() |
| 212 | .put(PI_ACTION_PARAM_ID_1, P4_ACTION_PARAM_MODEL_1) |
| 213 | .build(); |
| 214 | private static final ImmutableMap<PiActionParamId, PiActionParamModel> PI_ACTION_PARAMS_2 = |
| 215 | new ImmutableMap.Builder<PiActionParamId, PiActionParamModel>() |
| 216 | .put(PI_ACTION_PARAM_ID_2, P4_ACTION_PARAM_MODEL_2) |
| 217 | .build(); |
| 218 | |
| 219 | private static final PiActionModel P4_ACTION_MODEL_1 = new P4ActionModel(PI_ACTION_ID_1, PI_ACTION_PARAMS_1); |
| 220 | private static final PiActionModel P4_ACTION_MODEL_2 = new P4ActionModel(PI_ACTION_ID_2, PI_ACTION_PARAMS_2); |
| 221 | |
| 222 | private static final ImmutableMap<PiActionId, PiActionModel> ACTIONS_1 = |
| 223 | new ImmutableMap.Builder<PiActionId, PiActionModel>() |
| 224 | .put(PI_ACTION_ID_1, P4_ACTION_MODEL_1) |
| 225 | .build(); |
| 226 | |
| 227 | private static final ImmutableMap<PiActionId, PiActionModel> ACTIONS_2 = |
| 228 | new ImmutableMap.Builder<PiActionId, PiActionModel>() |
| 229 | .put(PI_ACTION_ID_2, P4_ACTION_MODEL_2) |
| 230 | .build(); |
| 231 | |
| 232 | /* Default Action */ |
| 233 | private static final PiActionId PI_ACTION_ID_DEFAULT_1 = PiActionId.of("DefaultAction1"); |
| 234 | private static final PiActionId PI_ACTION_ID_DEFAULT_2 = PiActionId.of("DefaultAction2"); |
| 235 | |
| 236 | private static final PiActionParamId PI_ACTION_PARAM_ID_DEFAULT_1 = PiActionParamId.of("DefaultActionParameter1"); |
| 237 | private static final PiActionParamId PI_ACTION_PARAM_ID_DEFAULT_2 = PiActionParamId.of("DefaultActionParameter2"); |
| 238 | |
| 239 | private static final int ACTION_PARAM_BIT_WIDTH_DEFAULT_1 = 8; |
| 240 | private static final int ACTION_PARAM_BIT_WIDTH_DEFAULT_2 = 16; |
| 241 | |
| 242 | private static final PiActionParamModel P4_ACTION_PARAM_MODEL_DEFAULT_1 = |
| 243 | new P4ActionParamModel(PI_ACTION_PARAM_ID_DEFAULT_1, ACTION_PARAM_BIT_WIDTH_DEFAULT_1); |
| 244 | private static final PiActionParamModel P4_ACTION_PARAM_MODEL_DEFAULT_2 = |
| 245 | new P4ActionParamModel(PI_ACTION_PARAM_ID_DEFAULT_2, ACTION_PARAM_BIT_WIDTH_DEFAULT_2); |
| 246 | |
| 247 | private static final ImmutableMap<PiActionParamId, PiActionParamModel> PI_ACTION_PARAMS_DEFAULT_1 = |
| 248 | new ImmutableMap.Builder<PiActionParamId, PiActionParamModel>() |
| 249 | .put(PI_ACTION_PARAM_ID_DEFAULT_1, P4_ACTION_PARAM_MODEL_DEFAULT_1) |
| 250 | .build(); |
| 251 | private static final ImmutableMap<PiActionParamId, PiActionParamModel> PI_ACTION_PARAMS_DEFAULT_2 = |
| 252 | new ImmutableMap.Builder<PiActionParamId, PiActionParamModel>() |
| 253 | .put(PI_ACTION_PARAM_ID_DEFAULT_2, P4_ACTION_PARAM_MODEL_DEFAULT_2) |
| 254 | .build(); |
| 255 | |
| 256 | private static final PiActionModel P4_ACTION_MODEL_DEFAULT_1 = |
| 257 | new P4ActionModel(PI_ACTION_ID_DEFAULT_1, PI_ACTION_PARAMS_DEFAULT_1); |
| 258 | private static final PiActionModel P4_ACTION_MODEL_DEFAULT_2 = |
| 259 | new P4ActionModel(PI_ACTION_ID_DEFAULT_2, PI_ACTION_PARAMS_DEFAULT_2); |
| 260 | |
| 261 | /* Table Models */ |
| 262 | private static final PiTableId PI_TABLE_ID_1 = PiTableId.of("Table1"); |
| 263 | private static final PiTableId PI_TABLE_ID_2 = PiTableId.of("Table2"); |
| 264 | |
| 265 | private static final PiTableType PI_TABLE_TYPE_1 = PiTableType.DIRECT; |
| 266 | private static final PiTableType PI_TABLE_TYPE_2 = PiTableType.INDIRECT; |
| 267 | |
| 268 | private static final long MAX_SIZE_1 = 10000; |
| 269 | private static final long MAX_SIZE_2 = 20000; |
| 270 | |
| 271 | private static final boolean SUPPORT_AGING_1 = true; |
| 272 | private static final boolean SUPPORT_AGING_2 = false; |
| 273 | |
Carmelo Cascone | 33b27bc | 2018-09-09 22:56:14 -0700 | [diff] [blame] | 274 | private static final boolean IS_CONST_TABLE_1 = true; |
| 275 | private static final boolean IS_CONST_TABLE_2 = false; |
| 276 | |
Mehmed Mustafa | 3e269df | 2017-11-24 17:19:49 +0300 | [diff] [blame] | 277 | private static final PiTableModel P4_TABLE_MODEL_1 = |
| 278 | new P4TableModel(PI_TABLE_ID_1, PI_TABLE_TYPE_1, P4_ACTION_PROFILE_MODEL_1, MAX_SIZE_1, COUNTERS_1, |
| 279 | METERS_1, SUPPORT_AGING_1, MATCH_FIELDS_1, ACTIONS_1, P4_ACTION_MODEL_DEFAULT_1, |
Carmelo Cascone | e45902b | 2018-12-18 13:30:45 -0800 | [diff] [blame^] | 280 | IS_CONST_TABLE_1); |
Mehmed Mustafa | 3e269df | 2017-11-24 17:19:49 +0300 | [diff] [blame] | 281 | private static final PiTableModel P4_TABLE_MODEL_2 = |
| 282 | new P4TableModel(PI_TABLE_ID_2, PI_TABLE_TYPE_2, P4_ACTION_PROFILE_MODEL_2, MAX_SIZE_2, COUNTERS_2, |
| 283 | METERS_2, SUPPORT_AGING_2, MATCH_FIELDS_2, ACTIONS_2, P4_ACTION_MODEL_DEFAULT_2, |
Carmelo Cascone | e45902b | 2018-12-18 13:30:45 -0800 | [diff] [blame^] | 284 | IS_CONST_TABLE_2); |
Mehmed Mustafa | 3e269df | 2017-11-24 17:19:49 +0300 | [diff] [blame] | 285 | |
| 286 | /* Packet operations */ |
| 287 | private static final PiPacketOperationType PI_PACKET_OPERATION_TYPE_1 = PiPacketOperationType.PACKET_IN; |
| 288 | private static final PiPacketOperationType PI_PACKET_OPERATION_TYPE_2 = PiPacketOperationType.PACKET_OUT; |
| 289 | |
| 290 | private static final PiControlMetadataId PI_CONTROL_METADATA_ID_1 = PiControlMetadataId.of("INGRESS PORT"); |
| 291 | private static final PiControlMetadataId PI_CONTROL_METADATA_ID_2 = PiControlMetadataId.of("EGRESS PORT"); |
| 292 | |
| 293 | private static final int META_BIT_WIDTH_1 = 32; |
| 294 | private static final int META_BIT_WIDTH_2 = 64; |
| 295 | |
| 296 | private static final PiControlMetadataModel P4_CONTROL_METADATA_MODEL_1 = |
| 297 | new P4ControlMetadataModel(PI_CONTROL_METADATA_ID_1, META_BIT_WIDTH_1); |
| 298 | private static final PiControlMetadataModel P4_CONTROL_METADATA_MODEL_2 = |
| 299 | new P4ControlMetadataModel(PI_CONTROL_METADATA_ID_2, META_BIT_WIDTH_2); |
| 300 | |
| 301 | /* Pipeline Models */ |
| 302 | private static final ImmutableMap<PiTableId, PiTableModel> TABLES_1 = |
| 303 | new ImmutableMap.Builder<PiTableId, PiTableModel>() |
| 304 | .put(PI_TABLE_ID_1, P4_TABLE_MODEL_1) |
| 305 | .build(); |
| 306 | private static final ImmutableMap<PiTableId, PiTableModel> TABLES_2 = |
| 307 | new ImmutableMap.Builder<PiTableId, PiTableModel>() |
| 308 | .put(PI_TABLE_ID_2, P4_TABLE_MODEL_2) |
| 309 | .build(); |
| 310 | |
| 311 | private static final ImmutableMap<PiActionProfileId, PiActionProfileModel> ACTION_PROFILES_1 = |
| 312 | new ImmutableMap.Builder<PiActionProfileId, PiActionProfileModel>() |
| 313 | .put(PI_ACTION_PROFILE_ID_1, P4_ACTION_PROFILE_MODEL_1) |
| 314 | .build(); |
| 315 | private static final ImmutableMap<PiActionProfileId, PiActionProfileModel> ACTION_PROFILES_2 = |
| 316 | new ImmutableMap.Builder<PiActionProfileId, PiActionProfileModel>() |
| 317 | .put(PI_ACTION_PROFILE_ID_2, P4_ACTION_PROFILE_MODEL_2) |
| 318 | .build(); |
| 319 | |
| 320 | private static final ImmutableList<PiControlMetadataModel> METADATAS_1 = |
| 321 | new ImmutableList.Builder<PiControlMetadataModel>() |
| 322 | .add(P4_CONTROL_METADATA_MODEL_1) |
| 323 | .build(); |
| 324 | private static final ImmutableList<PiControlMetadataModel> METADATAS_2 = |
| 325 | new ImmutableList.Builder<PiControlMetadataModel>() |
| 326 | .add(P4_CONTROL_METADATA_MODEL_2) |
| 327 | .build(); |
| 328 | |
| 329 | private static final PiPacketOperationModel P4_PACKET_OPERATION_MODEL_1 = |
| 330 | new P4PacketOperationModel(PI_PACKET_OPERATION_TYPE_1, METADATAS_1); |
| 331 | private static final PiPacketOperationModel P4_PACKET_OPERATION_MODEL_2 = |
| 332 | new P4PacketOperationModel(PI_PACKET_OPERATION_TYPE_2, METADATAS_2); |
| 333 | |
| 334 | private static final ImmutableMap<PiPacketOperationType, PiPacketOperationModel> PACKET_OPERATIONS_1 = |
| 335 | new ImmutableMap.Builder<PiPacketOperationType, PiPacketOperationModel>() |
| 336 | .put(PI_PACKET_OPERATION_TYPE_1, P4_PACKET_OPERATION_MODEL_1) |
| 337 | .build(); |
| 338 | private static final ImmutableMap<PiPacketOperationType, PiPacketOperationModel> PACKET_OPERATIONS_2 = |
| 339 | new ImmutableMap.Builder<PiPacketOperationType, PiPacketOperationModel>() |
| 340 | .put(PI_PACKET_OPERATION_TYPE_2, P4_PACKET_OPERATION_MODEL_2) |
| 341 | .build(); |
| 342 | |
| 343 | private static final PiPipelineModel P4_PIPELINE_MODEL_1 = |
FrankWang | 2674e45 | 2018-05-24 17:13:35 +0800 | [diff] [blame] | 344 | new P4PipelineModel(TABLES_1, COUNTERS_1, METERS_1, REGISTERS_1, ACTION_PROFILES_1, PACKET_OPERATIONS_1); |
Mehmed Mustafa | 3e269df | 2017-11-24 17:19:49 +0300 | [diff] [blame] | 345 | private static final PiPipelineModel SAME_AS_P4_PIPELINE_MODEL_1 = |
FrankWang | 2674e45 | 2018-05-24 17:13:35 +0800 | [diff] [blame] | 346 | new P4PipelineModel(TABLES_1, COUNTERS_1, METERS_1, REGISTERS_1, ACTION_PROFILES_1, PACKET_OPERATIONS_1); |
Mehmed Mustafa | 3e269df | 2017-11-24 17:19:49 +0300 | [diff] [blame] | 347 | private static final PiPipelineModel P4_PIPELINE_MODEL_2 = |
FrankWang | 2674e45 | 2018-05-24 17:13:35 +0800 | [diff] [blame] | 348 | new P4PipelineModel(TABLES_2, COUNTERS_2, METERS_2, REGISTERS_1, ACTION_PROFILES_2, PACKET_OPERATIONS_2); |
Mehmed Mustafa | 3e269df | 2017-11-24 17:19:49 +0300 | [diff] [blame] | 349 | |
| 350 | /** |
| 351 | * Checks that the P4PipelineModel class is immutable. |
| 352 | */ |
| 353 | @Test |
| 354 | public void testImmutability() { |
| 355 | assertThatClassIsImmutable(P4PipelineModel.class); |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * Checks the operation of equals(), hashCode() and toString() methods. |
| 360 | */ |
| 361 | @Test |
| 362 | public void testEquals() { |
| 363 | new EqualsTester() |
| 364 | .addEqualityGroup(P4_PIPELINE_MODEL_1, SAME_AS_P4_PIPELINE_MODEL_1) |
| 365 | .addEqualityGroup(P4_PIPELINE_MODEL_2) |
| 366 | .testEquals(); |
| 367 | } |
Carmelo Cascone | 33b27bc | 2018-09-09 22:56:14 -0700 | [diff] [blame] | 368 | } |