Various Bmv2 protocol refactorings in preparation of the flow rule
translator (ONOS-4044) - Added new classes for different match parameters (exact, ternary, lpm, valid) - Divided api package in two sub-packages, model (previously under drivers) and runtime (old api package) - Improved Bmv2ThriftClient caching and table entry handling Change-Id: I23c174cf3e8f9f6ecddb99c2d09dc531e8f1c73f
Showing
30 changed files
with
596 additions
and
166 deletions
| ... | @@ -20,10 +20,10 @@ import com.google.common.base.Preconditions; | ... | @@ -20,10 +20,10 @@ import com.google.common.base.Preconditions; |
| 20 | import com.google.common.collect.Lists; | 20 | import com.google.common.collect.Lists; |
| 21 | import com.google.common.collect.Maps; | 21 | import com.google.common.collect.Maps; |
| 22 | import com.google.common.collect.Sets; | 22 | import com.google.common.collect.Sets; |
| 23 | -import org.onosproject.bmv2.api.Bmv2ExtensionSelector; | 23 | +import org.onosproject.bmv2.api.runtime.Bmv2ExtensionSelector; |
| 24 | -import org.onosproject.bmv2.api.Bmv2ExtensionTreatment; | 24 | +import org.onosproject.bmv2.api.runtime.Bmv2ExtensionTreatment; |
| 25 | -import org.onosproject.bmv2.api.Bmv2TableEntry; | 25 | +import org.onosproject.bmv2.api.runtime.Bmv2TableEntry; |
| 26 | -import org.onosproject.bmv2.api.Bmv2Exception; | 26 | +import org.onosproject.bmv2.api.runtime.Bmv2RuntimeException; |
| 27 | import org.onosproject.bmv2.ctl.Bmv2ThriftClient; | 27 | import org.onosproject.bmv2.ctl.Bmv2ThriftClient; |
| 28 | import org.onosproject.net.driver.AbstractHandlerBehaviour; | 28 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 29 | import org.onosproject.net.flow.DefaultFlowEntry; | 29 | import org.onosproject.net.flow.DefaultFlowEntry; |
| ... | @@ -70,7 +70,7 @@ public class Bmv2FlowRuleDriver extends AbstractHandlerBehaviour | ... | @@ -70,7 +70,7 @@ public class Bmv2FlowRuleDriver extends AbstractHandlerBehaviour |
| 70 | Bmv2ThriftClient deviceClient; | 70 | Bmv2ThriftClient deviceClient; |
| 71 | try { | 71 | try { |
| 72 | deviceClient = getDeviceClient(); | 72 | deviceClient = getDeviceClient(); |
| 73 | - } catch (Bmv2Exception e) { | 73 | + } catch (Bmv2RuntimeException e) { |
| 74 | return Collections.emptyList(); | 74 | return Collections.emptyList(); |
| 75 | } | 75 | } |
| 76 | 76 | ||
| ... | @@ -107,7 +107,7 @@ public class Bmv2FlowRuleDriver extends AbstractHandlerBehaviour | ... | @@ -107,7 +107,7 @@ public class Bmv2FlowRuleDriver extends AbstractHandlerBehaviour |
| 107 | tableEntryIdsMap.put(rule, entryId); | 107 | tableEntryIdsMap.put(rule, entryId); |
| 108 | deviceEntriesMap.put(rule, new DefaultFlowEntry( | 108 | deviceEntriesMap.put(rule, new DefaultFlowEntry( |
| 109 | rule, FlowEntry.FlowEntryState.ADDED, 0, 0, 0)); | 109 | rule, FlowEntry.FlowEntryState.ADDED, 0, 0, 0)); |
| 110 | - } catch (Bmv2Exception e) { | 110 | + } catch (Bmv2RuntimeException e) { |
| 111 | log.error("Unable to update flow rule", e); | 111 | log.error("Unable to update flow rule", e); |
| 112 | continue; | 112 | continue; |
| 113 | } | 113 | } |
| ... | @@ -121,7 +121,7 @@ public class Bmv2FlowRuleDriver extends AbstractHandlerBehaviour | ... | @@ -121,7 +121,7 @@ public class Bmv2FlowRuleDriver extends AbstractHandlerBehaviour |
| 121 | tableEntryIdsMap.put(rule, entryId); | 121 | tableEntryIdsMap.put(rule, entryId); |
| 122 | deviceEntriesMap.put(rule, new DefaultFlowEntry( | 122 | deviceEntriesMap.put(rule, new DefaultFlowEntry( |
| 123 | rule, FlowEntry.FlowEntryState.ADDED, 0, 0, 0)); | 123 | rule, FlowEntry.FlowEntryState.ADDED, 0, 0, 0)); |
| 124 | - } catch (Bmv2Exception e) { | 124 | + } catch (Bmv2RuntimeException e) { |
| 125 | log.error("Unable to add flow rule", e); | 125 | log.error("Unable to add flow rule", e); |
| 126 | continue; | 126 | continue; |
| 127 | } | 127 | } |
| ... | @@ -138,7 +138,7 @@ public class Bmv2FlowRuleDriver extends AbstractHandlerBehaviour | ... | @@ -138,7 +138,7 @@ public class Bmv2FlowRuleDriver extends AbstractHandlerBehaviour |
| 138 | Bmv2ThriftClient deviceClient; | 138 | Bmv2ThriftClient deviceClient; |
| 139 | try { | 139 | try { |
| 140 | deviceClient = getDeviceClient(); | 140 | deviceClient = getDeviceClient(); |
| 141 | - } catch (Bmv2Exception e) { | 141 | + } catch (Bmv2RuntimeException e) { |
| 142 | return Collections.emptyList(); | 142 | return Collections.emptyList(); |
| 143 | } | 143 | } |
| 144 | 144 | ||
| ... | @@ -152,7 +152,7 @@ public class Bmv2FlowRuleDriver extends AbstractHandlerBehaviour | ... | @@ -152,7 +152,7 @@ public class Bmv2FlowRuleDriver extends AbstractHandlerBehaviour |
| 152 | 152 | ||
| 153 | try { | 153 | try { |
| 154 | deviceClient.deleteTableEntry(tableName, entryId); | 154 | deviceClient.deleteTableEntry(tableName, entryId); |
| 155 | - } catch (Bmv2Exception e) { | 155 | + } catch (Bmv2RuntimeException e) { |
| 156 | log.error("Unable to delete flow rule", e); | 156 | log.error("Unable to delete flow rule", e); |
| 157 | continue; | 157 | continue; |
| 158 | } | 158 | } |
| ... | @@ -225,10 +225,10 @@ public class Bmv2FlowRuleDriver extends AbstractHandlerBehaviour | ... | @@ -225,10 +225,10 @@ public class Bmv2FlowRuleDriver extends AbstractHandlerBehaviour |
| 225 | return "table" + String.valueOf(tableId); | 225 | return "table" + String.valueOf(tableId); |
| 226 | } | 226 | } |
| 227 | 227 | ||
| 228 | - private Bmv2ThriftClient getDeviceClient() throws Bmv2Exception { | 228 | + private Bmv2ThriftClient getDeviceClient() throws Bmv2RuntimeException { |
| 229 | try { | 229 | try { |
| 230 | return Bmv2ThriftClient.of(handler().data().deviceId()); | 230 | return Bmv2ThriftClient.of(handler().data().deviceId()); |
| 231 | - } catch (Bmv2Exception e) { | 231 | + } catch (Bmv2RuntimeException e) { |
| 232 | log.error("Failed to connect to Bmv2 device", e); | 232 | log.error("Failed to connect to Bmv2 device", e); |
| 233 | throw e; | 233 | throw e; |
| 234 | } | 234 | } | ... | ... |
| ... | @@ -18,7 +18,7 @@ package org.onosproject.drivers.bmv2; | ... | @@ -18,7 +18,7 @@ package org.onosproject.drivers.bmv2; |
| 18 | 18 | ||
| 19 | import com.google.common.collect.ImmutableList; | 19 | import com.google.common.collect.ImmutableList; |
| 20 | import com.google.common.collect.Lists; | 20 | import com.google.common.collect.Lists; |
| 21 | -import org.onosproject.bmv2.api.Bmv2Exception; | 21 | +import org.onosproject.bmv2.api.runtime.Bmv2RuntimeException; |
| 22 | import org.onosproject.bmv2.ctl.Bmv2ThriftClient; | 22 | import org.onosproject.bmv2.ctl.Bmv2ThriftClient; |
| 23 | import org.onosproject.net.DefaultAnnotations; | 23 | import org.onosproject.net.DefaultAnnotations; |
| 24 | import org.onosproject.net.PortNumber; | 24 | import org.onosproject.net.PortNumber; |
| ... | @@ -44,7 +44,7 @@ public class Bmv2PortGetterDriver extends AbstractHandlerBehaviour | ... | @@ -44,7 +44,7 @@ public class Bmv2PortGetterDriver extends AbstractHandlerBehaviour |
| 44 | Bmv2ThriftClient deviceClient; | 44 | Bmv2ThriftClient deviceClient; |
| 45 | try { | 45 | try { |
| 46 | deviceClient = Bmv2ThriftClient.of(handler().data().deviceId()); | 46 | deviceClient = Bmv2ThriftClient.of(handler().data().deviceId()); |
| 47 | - } catch (Bmv2Exception e) { | 47 | + } catch (Bmv2RuntimeException e) { |
| 48 | log.error("Failed to connect to Bmv2 device", e); | 48 | log.error("Failed to connect to Bmv2 device", e); |
| 49 | return Collections.emptyList(); | 49 | return Collections.emptyList(); |
| 50 | } | 50 | } |
| ... | @@ -68,7 +68,7 @@ public class Bmv2PortGetterDriver extends AbstractHandlerBehaviour | ... | @@ -68,7 +68,7 @@ public class Bmv2PortGetterDriver extends AbstractHandlerBehaviour |
| 68 | annotations | 68 | annotations |
| 69 | )); | 69 | )); |
| 70 | }); | 70 | }); |
| 71 | - } catch (Bmv2Exception e) { | 71 | + } catch (Bmv2RuntimeException e) { |
| 72 | log.error("Unable to get port description from Bmv2 device", e); | 72 | log.error("Unable to get port description from Bmv2 device", e); |
| 73 | } | 73 | } |
| 74 | 74 | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -14,7 +14,7 @@ | ... | @@ -14,7 +14,7 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.drivers.bmv2.model; | 17 | +package org.onosproject.bmv2.api.model; |
| 18 | 18 | ||
| 19 | import com.eclipsesource.json.JsonArray; | 19 | import com.eclipsesource.json.JsonArray; |
| 20 | import com.eclipsesource.json.JsonObject; | 20 | import com.eclipsesource.json.JsonObject; |
| ... | @@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableList; | ... | @@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableList; |
| 24 | import com.google.common.collect.Lists; | 24 | import com.google.common.collect.Lists; |
| 25 | import com.google.common.collect.Maps; | 25 | import com.google.common.collect.Maps; |
| 26 | import com.google.common.collect.Sets; | 26 | import com.google.common.collect.Sets; |
| 27 | +import org.onosproject.bmv2.api.runtime.Bmv2MatchParam; | ||
| 27 | 28 | ||
| 28 | import java.util.List; | 29 | import java.util.List; |
| 29 | import java.util.Map; | 30 | import java.util.Map; |
| ... | @@ -67,6 +68,7 @@ public final class Bmv2Model { | ... | @@ -67,6 +68,7 @@ public final class Bmv2Model { |
| 67 | */ | 68 | */ |
| 68 | public static Bmv2Model parse(JsonObject json) { | 69 | public static Bmv2Model parse(JsonObject json) { |
| 69 | checkArgument(json != null, "json cannot be null"); | 70 | checkArgument(json != null, "json cannot be null"); |
| 71 | + // TODO: implement caching, no need to parse a json if we already have the model | ||
| 70 | Bmv2Model model = new Bmv2Model(json); | 72 | Bmv2Model model = new Bmv2Model(json); |
| 71 | model.doParse(); | 73 | model.doParse(); |
| 72 | return model; | 74 | return model; |
| ... | @@ -335,7 +337,27 @@ public final class Bmv2Model { | ... | @@ -335,7 +337,27 @@ public final class Bmv2Model { |
| 335 | Bmv2ModelField field = new Bmv2ModelField( | 337 | Bmv2ModelField field = new Bmv2ModelField( |
| 336 | header, header.type().field(typeName)); | 338 | header, header.type().field(typeName)); |
| 337 | 339 | ||
| 338 | - String matchType = jKey.asObject().get("match_type").asString(); | 340 | + String matchTypeStr = jKey.asObject().get("match_type").asString(); |
| 341 | + | ||
| 342 | + Bmv2MatchParam.Type matchType; | ||
| 343 | + | ||
| 344 | + switch (matchTypeStr) { | ||
| 345 | + case "ternary": | ||
| 346 | + matchType = Bmv2MatchParam.Type.TERNARY; | ||
| 347 | + break; | ||
| 348 | + case "exact": | ||
| 349 | + matchType = Bmv2MatchParam.Type.EXACT; | ||
| 350 | + break; | ||
| 351 | + case "lpm": | ||
| 352 | + matchType = Bmv2MatchParam.Type.LPM; | ||
| 353 | + break; | ||
| 354 | + case "valid": | ||
| 355 | + matchType = Bmv2MatchParam.Type.VALID; | ||
| 356 | + break; | ||
| 357 | + default: | ||
| 358 | + throw new RuntimeException( | ||
| 359 | + "Unable to parse match type: " + matchTypeStr); | ||
| 360 | + } | ||
| 339 | 361 | ||
| 340 | keys.add(new Bmv2ModelTableKey(matchType, field)); | 362 | keys.add(new Bmv2ModelTableKey(matchType, field)); |
| 341 | }); | 363 | }); | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -14,7 +14,7 @@ | ... | @@ -14,7 +14,7 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.drivers.bmv2.model; | 17 | +package org.onosproject.bmv2.api.model; |
| 18 | 18 | ||
| 19 | import com.google.common.collect.ImmutableList; | 19 | import com.google.common.collect.ImmutableList; |
| 20 | import com.google.common.collect.Maps; | 20 | import com.google.common.collect.Maps; | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -14,7 +14,7 @@ | ... | @@ -14,7 +14,7 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.drivers.bmv2.model; | 17 | +package org.onosproject.bmv2.api.model; |
| 18 | 18 | ||
| 19 | import com.google.common.base.Objects; | 19 | import com.google.common.base.Objects; |
| 20 | 20 | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -14,7 +14,7 @@ | ... | @@ -14,7 +14,7 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.drivers.bmv2.model; | 17 | +package org.onosproject.bmv2.api.model; |
| 18 | 18 | ||
| 19 | import com.google.common.base.Objects; | 19 | import com.google.common.base.Objects; |
| 20 | 20 | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -14,7 +14,7 @@ | ... | @@ -14,7 +14,7 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.drivers.bmv2.model; | 17 | +package org.onosproject.bmv2.api.model; |
| 18 | 18 | ||
| 19 | import com.google.common.base.Objects; | 19 | import com.google.common.base.Objects; |
| 20 | 20 | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -14,7 +14,7 @@ | ... | @@ -14,7 +14,7 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.drivers.bmv2.model; | 17 | +package org.onosproject.bmv2.api.model; |
| 18 | 18 | ||
| 19 | import com.google.common.base.Objects; | 19 | import com.google.common.base.Objects; |
| 20 | import com.google.common.collect.ImmutableList; | 20 | import com.google.common.collect.ImmutableList; | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -14,7 +14,7 @@ | ... | @@ -14,7 +14,7 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.drivers.bmv2.model; | 17 | +package org.onosproject.bmv2.api.model; |
| 18 | 18 | ||
| 19 | import java.util.Objects; | 19 | import java.util.Objects; |
| 20 | 20 | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -14,7 +14,7 @@ | ... | @@ -14,7 +14,7 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.drivers.bmv2.model; | 17 | +package org.onosproject.bmv2.api.model; |
| 18 | 18 | ||
| 19 | import com.google.common.base.Objects; | 19 | import com.google.common.base.Objects; |
| 20 | 20 | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -14,9 +14,10 @@ | ... | @@ -14,9 +14,10 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.drivers.bmv2.model; | 17 | +package org.onosproject.bmv2.api.model; |
| 18 | 18 | ||
| 19 | import com.google.common.base.Objects; | 19 | import com.google.common.base.Objects; |
| 20 | +import org.onosproject.bmv2.api.runtime.Bmv2MatchParam; | ||
| 20 | 21 | ||
| 21 | import static com.google.common.base.MoreObjects.toStringHelper; | 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 22 | 23 | ||
| ... | @@ -25,7 +26,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -25,7 +26,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | */ | 26 | */ |
| 26 | public final class Bmv2ModelTableKey { | 27 | public final class Bmv2ModelTableKey { |
| 27 | 28 | ||
| 28 | - private final String matchType; | 29 | + private final Bmv2MatchParam.Type matchType; |
| 29 | private final Bmv2ModelField field; | 30 | private final Bmv2ModelField field; |
| 30 | 31 | ||
| 31 | /** | 32 | /** |
| ... | @@ -34,7 +35,7 @@ public final class Bmv2ModelTableKey { | ... | @@ -34,7 +35,7 @@ public final class Bmv2ModelTableKey { |
| 34 | * @param matchType match type | 35 | * @param matchType match type |
| 35 | * @param field field instance | 36 | * @param field field instance |
| 36 | */ | 37 | */ |
| 37 | - protected Bmv2ModelTableKey(String matchType, Bmv2ModelField field) { | 38 | + protected Bmv2ModelTableKey(Bmv2MatchParam.Type matchType, Bmv2ModelField field) { |
| 38 | this.matchType = matchType; | 39 | this.matchType = matchType; |
| 39 | this.field = field; | 40 | this.field = field; |
| 40 | } | 41 | } |
| ... | @@ -45,7 +46,7 @@ public final class Bmv2ModelTableKey { | ... | @@ -45,7 +46,7 @@ public final class Bmv2ModelTableKey { |
| 45 | * @return a string value | 46 | * @return a string value |
| 46 | * TODO returns enum of match type | 47 | * TODO returns enum of match type |
| 47 | */ | 48 | */ |
| 48 | - public String matchType() { | 49 | + public Bmv2MatchParam.Type matchType() { |
| 49 | return matchType; | 50 | return matchType; |
| 50 | } | 51 | } |
| 51 | 52 | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -17,4 +17,4 @@ | ... | @@ -17,4 +17,4 @@ |
| 17 | /** | 17 | /** |
| 18 | * BMv2 configuration model classes. | 18 | * BMv2 configuration model classes. |
| 19 | */ | 19 | */ |
| 20 | -package org.onosproject.drivers.bmv2.model; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 20 | +package org.onosproject.bmv2.api.model; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -16,5 +16,10 @@ | ... | @@ -16,5 +16,10 @@ |
| 16 | 16 | ||
| 17 | /** | 17 | /** |
| 18 | * Bmv2 API abstractions. | 18 | * Bmv2 API abstractions. |
| 19 | + * <p> | ||
| 20 | + * Bmv2 APIs are divided in two sub-packages, runtime and model. | ||
| 21 | + * Runtime APIs are used to represent operations that can be performed at runtime | ||
| 22 | + * on a Bmv2 device, while model APIs are used to describe the Bmv2 packet | ||
| 23 | + * processing model. | ||
| 19 | */ | 24 | */ |
| 20 | package org.onosproject.bmv2.api; | 25 | package org.onosproject.bmv2.api; |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -14,27 +14,28 @@ | ... | @@ -14,27 +14,28 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.bmv2.api; | 17 | +package org.onosproject.bmv2.api.runtime; |
| 18 | 18 | ||
| 19 | import com.google.common.base.MoreObjects; | 19 | import com.google.common.base.MoreObjects; |
| 20 | import com.google.common.collect.Lists; | 20 | import com.google.common.collect.Lists; |
| 21 | +import org.onlab.util.ImmutableByteSequence; | ||
| 21 | 22 | ||
| 22 | -import java.nio.ByteBuffer; | ||
| 23 | import java.util.Collections; | 23 | import java.util.Collections; |
| 24 | import java.util.List; | 24 | import java.util.List; |
| 25 | import java.util.Objects; | 25 | import java.util.Objects; |
| 26 | 26 | ||
| 27 | import static com.google.common.base.Preconditions.checkNotNull; | 27 | import static com.google.common.base.Preconditions.checkNotNull; |
| 28 | +import static com.google.common.base.Preconditions.checkState; | ||
| 28 | 29 | ||
| 29 | /** | 30 | /** |
| 30 | - * Bmv2 Action representation. | 31 | + * Bmv2 action representation. |
| 31 | */ | 32 | */ |
| 32 | public final class Bmv2Action { | 33 | public final class Bmv2Action { |
| 33 | 34 | ||
| 34 | private final String name; | 35 | private final String name; |
| 35 | - private final List<ByteBuffer> parameters; | 36 | + private final List<ImmutableByteSequence> parameters; |
| 36 | 37 | ||
| 37 | - private Bmv2Action(String name, List<ByteBuffer> parameters) { | 38 | + private Bmv2Action(String name, List<ImmutableByteSequence> parameters) { |
| 38 | // hide constructor | 39 | // hide constructor |
| 39 | this.name = name; | 40 | this.name = name; |
| 40 | this.parameters = parameters; | 41 | this.parameters = parameters; |
| ... | @@ -48,7 +49,7 @@ public final class Bmv2Action { | ... | @@ -48,7 +49,7 @@ public final class Bmv2Action { |
| 48 | } | 49 | } |
| 49 | 50 | ||
| 50 | /** | 51 | /** |
| 51 | - * Get action name. | 52 | + * Return the name of this action. |
| 52 | * | 53 | * |
| 53 | * @return action name | 54 | * @return action name |
| 54 | */ | 55 | */ |
| ... | @@ -57,11 +58,12 @@ public final class Bmv2Action { | ... | @@ -57,11 +58,12 @@ public final class Bmv2Action { |
| 57 | } | 58 | } |
| 58 | 59 | ||
| 59 | /** | 60 | /** |
| 60 | - * Get list of action parameters ordered as per P4 action definition. | 61 | + * Returns an immutable view of the ordered list of parameters of this |
| 62 | + * action. | ||
| 61 | * | 63 | * |
| 62 | - * @return List of action parameters | 64 | + * @return list of byte sequence |
| 63 | */ | 65 | */ |
| 64 | - public final List<ByteBuffer> parameters() { | 66 | + public final List<ImmutableByteSequence> parameters() { |
| 65 | return Collections.unmodifiableList(parameters); | 67 | return Collections.unmodifiableList(parameters); |
| 66 | } | 68 | } |
| 67 | 69 | ||
| ... | @@ -96,8 +98,8 @@ public final class Bmv2Action { | ... | @@ -96,8 +98,8 @@ public final class Bmv2Action { |
| 96 | */ | 98 | */ |
| 97 | public static final class Builder { | 99 | public static final class Builder { |
| 98 | 100 | ||
| 99 | - private String name; | 101 | + private String name = null; |
| 100 | - private List<ByteBuffer> parameters; | 102 | + private List<ImmutableByteSequence> parameters; |
| 101 | 103 | ||
| 102 | private Builder() { | 104 | private Builder() { |
| 103 | this.parameters = Lists.newArrayList(); | 105 | this.parameters = Lists.newArrayList(); |
| ... | @@ -110,7 +112,7 @@ public final class Bmv2Action { | ... | @@ -110,7 +112,7 @@ public final class Bmv2Action { |
| 110 | * @return this | 112 | * @return this |
| 111 | */ | 113 | */ |
| 112 | public Builder withName(String actionName) { | 114 | public Builder withName(String actionName) { |
| 113 | - this.name = actionName; | 115 | + this.name = checkNotNull(actionName); |
| 114 | return this; | 116 | return this; |
| 115 | } | 117 | } |
| 116 | 118 | ||
| ... | @@ -120,8 +122,8 @@ public final class Bmv2Action { | ... | @@ -120,8 +122,8 @@ public final class Bmv2Action { |
| 120 | * @param parameter a ByteBuffer value | 122 | * @param parameter a ByteBuffer value |
| 121 | * @return this | 123 | * @return this |
| 122 | */ | 124 | */ |
| 123 | - public Builder addParameter(ByteBuffer parameter) { | 125 | + public Builder addParameter(ImmutableByteSequence parameter) { |
| 124 | - parameters.add(parameter); | 126 | + parameters.add(checkNotNull(parameter)); |
| 125 | return this; | 127 | return this; |
| 126 | } | 128 | } |
| 127 | 129 | ||
| ... | @@ -131,7 +133,7 @@ public final class Bmv2Action { | ... | @@ -131,7 +133,7 @@ public final class Bmv2Action { |
| 131 | * @return a Bmv2 action | 133 | * @return a Bmv2 action |
| 132 | */ | 134 | */ |
| 133 | public Bmv2Action build() { | 135 | public Bmv2Action build() { |
| 134 | - checkNotNull(name, "Action name not set"); | 136 | + checkState(name != null, "action name not set"); |
| 135 | return new Bmv2Action(name, parameters); | 137 | return new Bmv2Action(name, parameters); |
| 136 | } | 138 | } |
| 137 | } | 139 | } | ... | ... |
| 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 | + | ||
| 19 | +import com.google.common.base.MoreObjects; | ||
| 20 | +import com.google.common.base.Objects; | ||
| 21 | +import org.onlab.util.ImmutableByteSequence; | ||
| 22 | + | ||
| 23 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * Representation of a Bmv2 exact match parameter. | ||
| 27 | + */ | ||
| 28 | +public class Bmv2ExactMatchParam implements Bmv2MatchParam { | ||
| 29 | + | ||
| 30 | + private final ImmutableByteSequence value; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * Creates a new match parameter object that matches exactly on the | ||
| 34 | + * given byte sequence. | ||
| 35 | + * | ||
| 36 | + * @param value a byte sequence value | ||
| 37 | + */ | ||
| 38 | + public Bmv2ExactMatchParam(ImmutableByteSequence value) { | ||
| 39 | + this.value = checkNotNull(value, "value cannot be null"); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + @Override | ||
| 43 | + public Type type() { | ||
| 44 | + return Type.EXACT; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * Return the byte sequence value matched by this parameter. | ||
| 49 | + * | ||
| 50 | + * @return an immutable byte buffer value | ||
| 51 | + */ | ||
| 52 | + public ImmutableByteSequence value() { | ||
| 53 | + return this.value; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + @Override | ||
| 57 | + public int hashCode() { | ||
| 58 | + return Objects.hashCode(value); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + @Override | ||
| 62 | + public boolean equals(Object obj) { | ||
| 63 | + if (this == obj) { | ||
| 64 | + return true; | ||
| 65 | + } | ||
| 66 | + if (obj == null || getClass() != obj.getClass()) { | ||
| 67 | + return false; | ||
| 68 | + } | ||
| 69 | + final Bmv2ExactMatchParam other = (Bmv2ExactMatchParam) obj; | ||
| 70 | + return Objects.equal(this.value, other.value); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + @Override | ||
| 74 | + public String toString() { | ||
| 75 | + return MoreObjects.toStringHelper(this) | ||
| 76 | + .add("value", value) | ||
| 77 | + .toString(); | ||
| 78 | + } | ||
| 79 | +} |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -14,13 +14,16 @@ | ... | @@ -14,13 +14,16 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.bmv2.api; | 17 | +package org.onosproject.bmv2.api.runtime; |
| 18 | 18 | ||
| 19 | import org.onlab.util.KryoNamespace; | 19 | import org.onlab.util.KryoNamespace; |
| 20 | import org.onosproject.net.flow.AbstractExtension; | 20 | import org.onosproject.net.flow.AbstractExtension; |
| 21 | import org.onosproject.net.flow.criteria.ExtensionSelector; | 21 | import org.onosproject.net.flow.criteria.ExtensionSelector; |
| 22 | import org.onosproject.net.flow.criteria.ExtensionSelectorType; | 22 | import org.onosproject.net.flow.criteria.ExtensionSelectorType; |
| 23 | 23 | ||
| 24 | +/** | ||
| 25 | + * Extension selector for Bmv2 used as a wrapper for a {@link Bmv2MatchKey}. | ||
| 26 | + */ | ||
| 24 | public class Bmv2ExtensionSelector extends AbstractExtension implements ExtensionSelector { | 27 | public class Bmv2ExtensionSelector extends AbstractExtension implements ExtensionSelector { |
| 25 | 28 | ||
| 26 | private final KryoNamespace appKryo = new KryoNamespace.Builder().build(); | 29 | private final KryoNamespace appKryo = new KryoNamespace.Builder().build(); | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -14,13 +14,16 @@ | ... | @@ -14,13 +14,16 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.bmv2.api; | 17 | +package org.onosproject.bmv2.api.runtime; |
| 18 | 18 | ||
| 19 | import org.onlab.util.KryoNamespace; | 19 | import org.onlab.util.KryoNamespace; |
| 20 | import org.onosproject.net.flow.AbstractExtension; | 20 | import org.onosproject.net.flow.AbstractExtension; |
| 21 | import org.onosproject.net.flow.instructions.ExtensionTreatment; | 21 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 22 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; | 22 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 23 | 23 | ||
| 24 | +/** | ||
| 25 | + * Extension treatment for Bmv2 used as a wrapper for a {@link Bmv2Action}. | ||
| 26 | + */ | ||
| 24 | public class Bmv2ExtensionTreatment extends AbstractExtension implements ExtensionTreatment { | 27 | public class Bmv2ExtensionTreatment extends AbstractExtension implements ExtensionTreatment { |
| 25 | 28 | ||
| 26 | private final KryoNamespace appKryo = new KryoNamespace.Builder().build(); | 29 | private final KryoNamespace appKryo = new KryoNamespace.Builder().build(); | ... | ... |
| 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 | + | ||
| 19 | +import com.google.common.base.MoreObjects; | ||
| 20 | +import com.google.common.base.Objects; | ||
| 21 | +import org.onlab.util.ImmutableByteSequence; | ||
| 22 | + | ||
| 23 | +import static com.google.common.base.Preconditions.checkArgument; | ||
| 24 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * Representation of a Bmv2 longest prefix match (LPM) parameter. | ||
| 28 | + */ | ||
| 29 | +public class Bmv2LpmMatchParam implements Bmv2MatchParam { | ||
| 30 | + | ||
| 31 | + private final ImmutableByteSequence value; | ||
| 32 | + private final int prefixLength; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * Creates a new LPM parameter using the given byte sequence value and | ||
| 36 | + * prefix length. | ||
| 37 | + * | ||
| 38 | + * @param value a byte sequence value | ||
| 39 | + * @param prefixLength an integer value | ||
| 40 | + */ | ||
| 41 | + public Bmv2LpmMatchParam(ImmutableByteSequence value, int prefixLength) { | ||
| 42 | + checkArgument(prefixLength >= 0, "prefix length cannot be negative"); | ||
| 43 | + this.value = checkNotNull(value); | ||
| 44 | + this.prefixLength = prefixLength; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public Bmv2MatchParam.Type type() { | ||
| 49 | + return Type.LPM; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * Returns the byte sequence value of this parameter. | ||
| 54 | + * | ||
| 55 | + * @return a byte sequence value | ||
| 56 | + */ | ||
| 57 | + public ImmutableByteSequence value() { | ||
| 58 | + return this.value; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * Returns the prefix length of this parameter. | ||
| 63 | + * | ||
| 64 | + * @return an integer value | ||
| 65 | + */ | ||
| 66 | + public int prefixLength() { | ||
| 67 | + return this.prefixLength; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + @Override | ||
| 71 | + public int hashCode() { | ||
| 72 | + return Objects.hashCode(value, prefixLength); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + @Override | ||
| 76 | + public boolean equals(Object obj) { | ||
| 77 | + if (this == obj) { | ||
| 78 | + return true; | ||
| 79 | + } | ||
| 80 | + if (obj == null || getClass() != obj.getClass()) { | ||
| 81 | + return false; | ||
| 82 | + } | ||
| 83 | + final Bmv2LpmMatchParam other = (Bmv2LpmMatchParam) obj; | ||
| 84 | + return Objects.equal(this.value, other.value) | ||
| 85 | + && Objects.equal(this.prefixLength, other.prefixLength); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + @Override | ||
| 89 | + public String toString() { | ||
| 90 | + return MoreObjects.toStringHelper(this) | ||
| 91 | + .add("value", value) | ||
| 92 | + .add("prefixLength", prefixLength) | ||
| 93 | + .toString(); | ||
| 94 | + } | ||
| 95 | +} |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -14,36 +14,28 @@ | ... | @@ -14,36 +14,28 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.bmv2.api; | 17 | +package org.onosproject.bmv2.api.runtime; |
| 18 | 18 | ||
| 19 | import com.google.common.base.MoreObjects; | 19 | import com.google.common.base.MoreObjects; |
| 20 | import com.google.common.collect.Lists; | 20 | import com.google.common.collect.Lists; |
| 21 | -import org.p4.bmv2.thrift.BmMatchParam; | 21 | +import org.onlab.util.ImmutableByteSequence; |
| 22 | -import org.p4.bmv2.thrift.BmMatchParamExact; | 22 | + |
| 23 | -import org.p4.bmv2.thrift.BmMatchParamLPM; | ||
| 24 | -import org.p4.bmv2.thrift.BmMatchParamTernary; | ||
| 25 | -import org.p4.bmv2.thrift.BmMatchParamType; | ||
| 26 | -import org.p4.bmv2.thrift.BmMatchParamValid; | ||
| 27 | - | ||
| 28 | -import java.nio.ByteBuffer; | ||
| 29 | -import java.util.Arrays; | ||
| 30 | import java.util.Collections; | 23 | import java.util.Collections; |
| 31 | import java.util.List; | 24 | import java.util.List; |
| 32 | import java.util.Objects; | 25 | import java.util.Objects; |
| 33 | 26 | ||
| 27 | +import static com.google.common.base.Preconditions.checkArgument; | ||
| 28 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 29 | + | ||
| 34 | /** | 30 | /** |
| 35 | * Bmv2 match key representation. | 31 | * Bmv2 match key representation. |
| 36 | */ | 32 | */ |
| 37 | public final class Bmv2MatchKey { | 33 | public final class Bmv2MatchKey { |
| 38 | 34 | ||
| 39 | - private final List<BmMatchParam> matchParams; | 35 | + private final List<Bmv2MatchParam> matchParams; |
| 40 | 36 | ||
| 41 | - /** | 37 | + private Bmv2MatchKey(List<Bmv2MatchParam> matchParams) { |
| 42 | - * Creates a new match key. | 38 | + // ban constructor |
| 43 | - * | ||
| 44 | - * @param matchParams The ordered list of match parameters | ||
| 45 | - */ | ||
| 46 | - private Bmv2MatchKey(List<BmMatchParam> matchParams) { | ||
| 47 | this.matchParams = matchParams; | 39 | this.matchParams = matchParams; |
| 48 | } | 40 | } |
| 49 | 41 | ||
| ... | @@ -52,11 +44,12 @@ public final class Bmv2MatchKey { | ... | @@ -52,11 +44,12 @@ public final class Bmv2MatchKey { |
| 52 | } | 44 | } |
| 53 | 45 | ||
| 54 | /** | 46 | /** |
| 55 | - * Returns the match parameters defined for this match key (read-only). | 47 | + * Returns an immutable view of the ordered list of match parameters of this |
| 48 | + * match key. | ||
| 56 | * | 49 | * |
| 57 | - * @return match parameters | 50 | + * @return list match parameters |
| 58 | */ | 51 | */ |
| 59 | - public final List<BmMatchParam> bmMatchParams() { | 52 | + public final List<Bmv2MatchParam> matchParams() { |
| 60 | return Collections.unmodifiableList(matchParams); | 53 | return Collections.unmodifiableList(matchParams); |
| 61 | } | 54 | } |
| 62 | 55 | ||
| ... | @@ -90,77 +83,28 @@ public final class Bmv2MatchKey { | ... | @@ -90,77 +83,28 @@ public final class Bmv2MatchKey { |
| 90 | */ | 83 | */ |
| 91 | public static final class Builder { | 84 | public static final class Builder { |
| 92 | 85 | ||
| 93 | - private List<BmMatchParam> matchParams; | 86 | + private List<Bmv2MatchParam> matchParams; |
| 94 | 87 | ||
| 95 | private Builder() { | 88 | private Builder() { |
| 96 | this.matchParams = Lists.newArrayList(); | 89 | this.matchParams = Lists.newArrayList(); |
| 97 | } | 90 | } |
| 98 | 91 | ||
| 99 | - /** | 92 | + public Builder add(Bmv2MatchParam param) { |
| 100 | - * Adds an exact match parameter. | 93 | + this.matchParams.add(checkNotNull(param)); |
| 101 | - * | ||
| 102 | - * @param key a ByteBuffer value | ||
| 103 | - * @return this | ||
| 104 | - */ | ||
| 105 | - public Builder withExact(ByteBuffer key) { | ||
| 106 | - this.matchParams.add( | ||
| 107 | - new BmMatchParam(BmMatchParamType.EXACT) | ||
| 108 | - .setExact(new BmMatchParamExact(key))); | ||
| 109 | - return this; | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | - | ||
| 113 | - /** | ||
| 114 | - * Adds a longest prefix match parameter. | ||
| 115 | - * | ||
| 116 | - * @param key a ByteBuffer value | ||
| 117 | - * @param prefixLength an integer value | ||
| 118 | - * @return this | ||
| 119 | - */ | ||
| 120 | - public Builder withLpm(ByteBuffer key, int prefixLength) { | ||
| 121 | - this.matchParams.add( | ||
| 122 | - new BmMatchParam(BmMatchParamType.LPM) | ||
| 123 | - .setLpm(new BmMatchParamLPM(key, prefixLength))); | ||
| 124 | - return this; | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - /** | ||
| 128 | - * Adds a ternary match parameter. | ||
| 129 | - * | ||
| 130 | - * @param key a ByteBuffer value | ||
| 131 | - * @param mask an ByteBuffer value | ||
| 132 | - * @return this | ||
| 133 | - */ | ||
| 134 | - public Builder withTernary(ByteBuffer key, ByteBuffer mask) { | ||
| 135 | - this.matchParams.add( | ||
| 136 | - new BmMatchParam(BmMatchParamType.TERNARY). | ||
| 137 | - setTernary(new BmMatchParamTernary(key, mask))); | ||
| 138 | return this; | 94 | return this; |
| 139 | } | 95 | } |
| 140 | 96 | ||
| 141 | /** | 97 | /** |
| 142 | * Adds a ternary match parameter where all bits are don't-care. | 98 | * Adds a ternary match parameter where all bits are don't-care. |
| 143 | * | 99 | * |
| 144 | - * @param byteLength an integer value representing the length in byte of the parameter | 100 | + * @param byteLength length in bytes of the parameter |
| 145 | * @return this | 101 | * @return this |
| 146 | */ | 102 | */ |
| 147 | public Builder withWildcard(int byteLength) { | 103 | public Builder withWildcard(int byteLength) { |
| 148 | - byte[] zeros = new byte[byteLength]; | 104 | + checkArgument(byteLength > 0, "length must be a positive integer"); |
| 149 | - Arrays.fill(zeros, (byte) 0); | 105 | + return add(new Bmv2TernaryMatchParam( |
| 150 | - return this.withTernary(ByteBuffer.wrap(zeros), ByteBuffer.wrap(zeros)); | 106 | + ImmutableByteSequence.ofZeros(byteLength), |
| 151 | - } | 107 | + ImmutableByteSequence.ofZeros(byteLength))); |
| 152 | - | ||
| 153 | - /** | ||
| 154 | - * Adds a valid match parameter. | ||
| 155 | - * | ||
| 156 | - * @param key a boolean value | ||
| 157 | - * @return this | ||
| 158 | - */ | ||
| 159 | - public Builder withValid(boolean key) { | ||
| 160 | - this.matchParams.add( | ||
| 161 | - new BmMatchParam(BmMatchParamType.VALID) | ||
| 162 | - .setValid(new BmMatchParamValid(key))); | ||
| 163 | - return this; | ||
| 164 | } | 108 | } |
| 165 | 109 | ||
| 166 | /** | 110 | /** | ... | ... |
| 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 | + | ||
| 19 | +/** | ||
| 20 | + * Representation of a Bmv2 match parameter. | ||
| 21 | + */ | ||
| 22 | +public interface Bmv2MatchParam { | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * Returns the match type of this parameter. | ||
| 26 | + * | ||
| 27 | + * @return a match type value | ||
| 28 | + */ | ||
| 29 | + Type type(); | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * Bmv2 match types. | ||
| 33 | + */ | ||
| 34 | + enum Type { | ||
| 35 | + /** | ||
| 36 | + * Exact match type. | ||
| 37 | + */ | ||
| 38 | + EXACT, | ||
| 39 | + /** | ||
| 40 | + * Ternary match type. | ||
| 41 | + */ | ||
| 42 | + TERNARY, | ||
| 43 | + /** | ||
| 44 | + * Longest-prefix match type. | ||
| 45 | + */ | ||
| 46 | + LPM, | ||
| 47 | + /** | ||
| 48 | + * Valid match type. | ||
| 49 | + */ | ||
| 50 | + VALID; | ||
| 51 | + } | ||
| 52 | +} |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -14,7 +14,7 @@ | ... | @@ -14,7 +14,7 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.bmv2.api; | 17 | +package org.onosproject.bmv2.api.runtime; |
| 18 | 18 | ||
| 19 | import com.google.common.base.MoreObjects; | 19 | import com.google.common.base.MoreObjects; |
| 20 | import org.p4.bmv2.thrift.DevMgrPortInfo; | 20 | import org.p4.bmv2.thrift.DevMgrPortInfo; | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -14,14 +14,18 @@ | ... | @@ -14,14 +14,18 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.bmv2.api; | 17 | +package org.onosproject.bmv2.api.runtime; |
| 18 | 18 | ||
| 19 | /** | 19 | /** |
| 20 | - * General Bmv2 exception. | 20 | + * General exception of the Bmv2 runtime APIs. |
| 21 | */ | 21 | */ |
| 22 | -public class Bmv2Exception extends Exception { | 22 | +public class Bmv2RuntimeException extends Exception { |
| 23 | 23 | ||
| 24 | - public Bmv2Exception(String message, Throwable cause) { | 24 | + public Bmv2RuntimeException(String message, Throwable cause) { |
| 25 | super(message, cause); | 25 | super(message, cause); |
| 26 | } | 26 | } |
| 27 | + | ||
| 28 | + public Bmv2RuntimeException(String message) { | ||
| 29 | + super(message); | ||
| 30 | + } | ||
| 27 | } | 31 | } | ... | ... |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -14,12 +14,13 @@ | ... | @@ -14,12 +14,13 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.bmv2.api; | 17 | +package org.onosproject.bmv2.api.runtime; |
| 18 | - | ||
| 19 | -import com.google.common.base.Preconditions; | ||
| 20 | 18 | ||
| 21 | import java.util.Objects; | 19 | import java.util.Objects; |
| 22 | 20 | ||
| 21 | +import static com.google.common.base.Preconditions.checkArgument; | ||
| 22 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 23 | + | ||
| 23 | /** | 24 | /** |
| 24 | * Bmv2 representation of a table entry. | 25 | * Bmv2 representation of a table entry. |
| 25 | */ | 26 | */ |
| ... | @@ -43,6 +44,11 @@ public final class Bmv2TableEntry { | ... | @@ -43,6 +44,11 @@ public final class Bmv2TableEntry { |
| 43 | this.timeout = timeout; | 44 | this.timeout = timeout; |
| 44 | } | 45 | } |
| 45 | 46 | ||
| 47 | + /** | ||
| 48 | + * Returns a new Bmv2 table entry builder. | ||
| 49 | + * | ||
| 50 | + * @return a new builder. | ||
| 51 | + */ | ||
| 46 | public static Builder builder() { | 52 | public static Builder builder() { |
| 47 | return new Builder(); | 53 | return new Builder(); |
| 48 | } | 54 | } |
| ... | @@ -159,7 +165,7 @@ public final class Bmv2TableEntry { | ... | @@ -159,7 +165,7 @@ public final class Bmv2TableEntry { |
| 159 | * @return this | 165 | * @return this |
| 160 | */ | 166 | */ |
| 161 | public Builder withTableName(String tableName) { | 167 | public Builder withTableName(String tableName) { |
| 162 | - this.tableName = tableName; | 168 | + this.tableName = checkNotNull(tableName, "table name cannot be null"); |
| 163 | return this; | 169 | return this; |
| 164 | } | 170 | } |
| 165 | 171 | ||
| ... | @@ -170,7 +176,7 @@ public final class Bmv2TableEntry { | ... | @@ -170,7 +176,7 @@ public final class Bmv2TableEntry { |
| 170 | * @return this | 176 | * @return this |
| 171 | */ | 177 | */ |
| 172 | public Builder withMatchKey(Bmv2MatchKey matchKey) { | 178 | public Builder withMatchKey(Bmv2MatchKey matchKey) { |
| 173 | - this.matchKey = matchKey; | 179 | + this.matchKey = checkNotNull(matchKey, "match key cannot be null"); |
| 174 | return this; | 180 | return this; |
| 175 | } | 181 | } |
| 176 | 182 | ||
| ... | @@ -181,11 +187,12 @@ public final class Bmv2TableEntry { | ... | @@ -181,11 +187,12 @@ public final class Bmv2TableEntry { |
| 181 | * @return this | 187 | * @return this |
| 182 | */ | 188 | */ |
| 183 | public Builder withAction(Bmv2Action action) { | 189 | public Builder withAction(Bmv2Action action) { |
| 184 | - this.action = action; | 190 | + this.action = checkNotNull(action, "action cannot be null"); |
| 185 | return this; | 191 | return this; |
| 186 | } | 192 | } |
| 187 | 193 | ||
| 188 | public Builder withPriority(int priority) { | 194 | public Builder withPriority(int priority) { |
| 195 | + checkArgument(priority >= 0, "priority cannot be negative"); | ||
| 189 | this.priority = priority; | 196 | this.priority = priority; |
| 190 | return this; | 197 | return this; |
| 191 | } | 198 | } |
| ... | @@ -197,6 +204,7 @@ public final class Bmv2TableEntry { | ... | @@ -197,6 +204,7 @@ public final class Bmv2TableEntry { |
| 197 | * @return this | 204 | * @return this |
| 198 | */ | 205 | */ |
| 199 | public Builder withTimeout(double timeout) { | 206 | public Builder withTimeout(double timeout) { |
| 207 | + checkArgument(timeout > 0, "timeout must be a positive non-zero value"); | ||
| 200 | this.timeout = timeout; | 208 | this.timeout = timeout; |
| 201 | return this; | 209 | return this; |
| 202 | } | 210 | } |
| ... | @@ -207,10 +215,6 @@ public final class Bmv2TableEntry { | ... | @@ -207,10 +215,6 @@ public final class Bmv2TableEntry { |
| 207 | * @return a new table entry object | 215 | * @return a new table entry object |
| 208 | */ | 216 | */ |
| 209 | public Bmv2TableEntry build() { | 217 | public Bmv2TableEntry build() { |
| 210 | - Preconditions.checkNotNull(tableName); | ||
| 211 | - Preconditions.checkNotNull(matchKey); | ||
| 212 | - Preconditions.checkNotNull(action); | ||
| 213 | - | ||
| 214 | return new Bmv2TableEntry(tableName, matchKey, action, priority, | 218 | return new Bmv2TableEntry(tableName, matchKey, action, priority, |
| 215 | timeout); | 219 | timeout); |
| 216 | 220 | ... | ... |
| 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 | + | ||
| 19 | +import com.google.common.base.MoreObjects; | ||
| 20 | +import com.google.common.base.Objects; | ||
| 21 | +import org.onlab.util.ImmutableByteSequence; | ||
| 22 | + | ||
| 23 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 24 | +import static com.google.common.base.Preconditions.checkState; | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * Representation of a Bmv2 ternary match parameter. | ||
| 28 | + */ | ||
| 29 | +public class Bmv2TernaryMatchParam implements Bmv2MatchParam { | ||
| 30 | + | ||
| 31 | + private final ImmutableByteSequence value; | ||
| 32 | + private final ImmutableByteSequence mask; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * Creates a new ternary match parameter using the given byte sequences of | ||
| 36 | + * value and mask. | ||
| 37 | + * | ||
| 38 | + * @param value a byte sequence value | ||
| 39 | + * @param mask a byte sequence value | ||
| 40 | + */ | ||
| 41 | + public Bmv2TernaryMatchParam(ImmutableByteSequence value, | ||
| 42 | + ImmutableByteSequence mask) { | ||
| 43 | + this.value = checkNotNull(value, "value cannot be null"); | ||
| 44 | + this.mask = checkNotNull(mask, "value cannot be null"); | ||
| 45 | + checkState(value.size() == mask.size(), | ||
| 46 | + "value and mask must have equal size"); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + @Override | ||
| 50 | + public Type type() { | ||
| 51 | + return Type.TERNARY; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * Returns the byte sequence value of by this parameter. | ||
| 56 | + * | ||
| 57 | + * @return a byte sequence value | ||
| 58 | + */ | ||
| 59 | + public ImmutableByteSequence value() { | ||
| 60 | + return this.value; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + /** | ||
| 64 | + * Returns the byte sequence mask of by this parameter. | ||
| 65 | + * | ||
| 66 | + * @return a byte sequence value | ||
| 67 | + */ | ||
| 68 | + public ImmutableByteSequence mask() { | ||
| 69 | + return this.mask; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + @Override | ||
| 73 | + public int hashCode() { | ||
| 74 | + return Objects.hashCode(value, mask); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + @Override | ||
| 78 | + public boolean equals(Object obj) { | ||
| 79 | + if (this == obj) { | ||
| 80 | + return true; | ||
| 81 | + } | ||
| 82 | + if (obj == null || getClass() != obj.getClass()) { | ||
| 83 | + return false; | ||
| 84 | + } | ||
| 85 | + final Bmv2TernaryMatchParam other = (Bmv2TernaryMatchParam) obj; | ||
| 86 | + return Objects.equal(this.value, other.value) | ||
| 87 | + && Objects.equal(this.mask, other.mask); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + @Override | ||
| 91 | + public String toString() { | ||
| 92 | + return MoreObjects.toStringHelper(this) | ||
| 93 | + .add("value", value) | ||
| 94 | + .add("mask", mask) | ||
| 95 | + .toString(); | ||
| 96 | + } | ||
| 97 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 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 | + | ||
| 19 | + | ||
| 20 | +import com.google.common.base.MoreObjects; | ||
| 21 | + | ||
| 22 | +import java.util.Objects; | ||
| 23 | + | ||
| 24 | +/** | ||
| 25 | + * Representation of a Bmv2 valid match parameter. | ||
| 26 | + */ | ||
| 27 | +public class Bmv2ValidMatchParam implements Bmv2MatchParam { | ||
| 28 | + | ||
| 29 | + private final boolean flag; | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * Creates a new valid match parameter using the given boolean flag. | ||
| 33 | + * | ||
| 34 | + * @param flag a boolean value | ||
| 35 | + */ | ||
| 36 | + public Bmv2ValidMatchParam(boolean flag) { | ||
| 37 | + this.flag = flag; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + @Override | ||
| 41 | + public Type type() { | ||
| 42 | + return Type.VALID; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * Returns the boolean flag of this parameter. | ||
| 47 | + * | ||
| 48 | + * @return a boolean value | ||
| 49 | + */ | ||
| 50 | + public boolean flag() { | ||
| 51 | + return flag; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + @Override | ||
| 55 | + public int hashCode() { | ||
| 56 | + return Objects.hashCode(flag); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + @Override | ||
| 60 | + public boolean equals(Object obj) { | ||
| 61 | + if (this == obj) { | ||
| 62 | + return true; | ||
| 63 | + } | ||
| 64 | + if (obj == null || getClass() != obj.getClass()) { | ||
| 65 | + return false; | ||
| 66 | + } | ||
| 67 | + final Bmv2ValidMatchParam other = (Bmv2ValidMatchParam) obj; | ||
| 68 | + return this.flag == other.flag; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public String toString() { | ||
| 73 | + return MoreObjects.toStringHelper(this) | ||
| 74 | + .add("flag", flag) | ||
| 75 | + .toString(); | ||
| 76 | + } | ||
| 77 | +} |
| 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 | +/** | ||
| 18 | + * Bmv2 runtime APIs. | ||
| 19 | + */ | ||
| 20 | +package org.onosproject.bmv2.api.runtime; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
This diff is collapsed. Click to expand it.
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -14,17 +14,14 @@ | ... | @@ -14,17 +14,14 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.drivers.bmv2; | 17 | +package org.onosproject.bmv2.api.model; |
| 18 | 18 | ||
| 19 | import com.eclipsesource.json.Json; | 19 | import com.eclipsesource.json.Json; |
| 20 | import com.eclipsesource.json.JsonObject; | 20 | import com.eclipsesource.json.JsonObject; |
| 21 | import com.google.common.testing.EqualsTester; | 21 | import com.google.common.testing.EqualsTester; |
| 22 | import org.junit.Before; | 22 | import org.junit.Before; |
| 23 | import org.junit.Test; | 23 | import org.junit.Test; |
| 24 | -import org.onosproject.drivers.bmv2.model.Bmv2Model; | 24 | +import org.onosproject.bmv2.api.runtime.Bmv2MatchParam; |
| 25 | -import org.onosproject.drivers.bmv2.model.Bmv2ModelAction; | ||
| 26 | -import org.onosproject.drivers.bmv2.model.Bmv2ModelHeaderType; | ||
| 27 | -import org.onosproject.drivers.bmv2.model.Bmv2ModelTable; | ||
| 28 | 25 | ||
| 29 | import java.io.BufferedReader; | 26 | import java.io.BufferedReader; |
| 30 | import java.io.InputStreamReader; | 27 | import java.io.InputStreamReader; |
| ... | @@ -156,7 +153,7 @@ public class Bmv2ModelTest { | ... | @@ -156,7 +153,7 @@ public class Bmv2ModelTest { |
| 156 | 153 | ||
| 157 | // key match type | 154 | // key match type |
| 158 | assertThat("Incorrect value for table key match type", | 155 | assertThat("Incorrect value for table key match type", |
| 159 | - table0.keys().get(0).matchType(), is(equalTo("ternary"))); | 156 | + table0.keys().get(0).matchType(), is(equalTo(Bmv2MatchParam.Type.TERNARY))); |
| 160 | 157 | ||
| 161 | // header type | 158 | // header type |
| 162 | assertThat("Incorrect value for table key header type", | 159 | assertThat("Incorrect value for table key header type", | ... | ... |
| ... | @@ -21,6 +21,7 @@ import com.google.common.base.Objects; | ... | @@ -21,6 +21,7 @@ import com.google.common.base.Objects; |
| 21 | 21 | ||
| 22 | import java.nio.ByteBuffer; | 22 | import java.nio.ByteBuffer; |
| 23 | import java.nio.ByteOrder; | 23 | import java.nio.ByteOrder; |
| 24 | +import java.util.Arrays; | ||
| 24 | 25 | ||
| 25 | import static com.google.common.base.Preconditions.checkArgument; | 26 | import static com.google.common.base.Preconditions.checkArgument; |
| 26 | import static org.apache.commons.lang3.ArrayUtils.reverse; | 27 | import static org.apache.commons.lang3.ArrayUtils.reverse; |
| ... | @@ -62,7 +63,7 @@ public final class ImmutableByteSequence { | ... | @@ -62,7 +63,7 @@ public final class ImmutableByteSequence { |
| 62 | * the passed byte array. | 63 | * the passed byte array. |
| 63 | * | 64 | * |
| 64 | * @param original a byte array value | 65 | * @param original a byte array value |
| 65 | - * @return a new immutable byte buffer | 66 | + * @return a new immutable byte sequence |
| 66 | */ | 67 | */ |
| 67 | public static ImmutableByteSequence copyFrom(byte[] original) { | 68 | public static ImmutableByteSequence copyFrom(byte[] original) { |
| 68 | checkArgument(original != null && original.length > 0, | 69 | checkArgument(original != null && original.length > 0, |
| ... | @@ -101,7 +102,7 @@ public final class ImmutableByteSequence { | ... | @@ -101,7 +102,7 @@ public final class ImmutableByteSequence { |
| 101 | * Creates a new byte sequence of 8 bytes containing the given long value. | 102 | * Creates a new byte sequence of 8 bytes containing the given long value. |
| 102 | * | 103 | * |
| 103 | * @param original a long value | 104 | * @param original a long value |
| 104 | - * @return a new immutable byte buffer | 105 | + * @return a new immutable byte sequence |
| 105 | */ | 106 | */ |
| 106 | public static ImmutableByteSequence copyFrom(long original) { | 107 | public static ImmutableByteSequence copyFrom(long original) { |
| 107 | return new ImmutableByteSequence( | 108 | return new ImmutableByteSequence( |
| ... | @@ -112,7 +113,7 @@ public final class ImmutableByteSequence { | ... | @@ -112,7 +113,7 @@ public final class ImmutableByteSequence { |
| 112 | * Creates a new byte sequence of 4 bytes containing the given int value. | 113 | * Creates a new byte sequence of 4 bytes containing the given int value. |
| 113 | * | 114 | * |
| 114 | * @param original an int value | 115 | * @param original an int value |
| 115 | - * @return a new immutable byte buffer | 116 | + * @return a new immutable byte sequence |
| 116 | */ | 117 | */ |
| 117 | public static ImmutableByteSequence copyFrom(int original) { | 118 | public static ImmutableByteSequence copyFrom(int original) { |
| 118 | return new ImmutableByteSequence( | 119 | return new ImmutableByteSequence( |
| ... | @@ -123,7 +124,7 @@ public final class ImmutableByteSequence { | ... | @@ -123,7 +124,7 @@ public final class ImmutableByteSequence { |
| 123 | * Creates a new byte sequence of 2 bytes containing the given short value. | 124 | * Creates a new byte sequence of 2 bytes containing the given short value. |
| 124 | * | 125 | * |
| 125 | * @param original a short value | 126 | * @param original a short value |
| 126 | - * @return a new immutable byte buffer | 127 | + * @return a new immutable byte sequence |
| 127 | */ | 128 | */ |
| 128 | public static ImmutableByteSequence copyFrom(short original) { | 129 | public static ImmutableByteSequence copyFrom(short original) { |
| 129 | return new ImmutableByteSequence( | 130 | return new ImmutableByteSequence( |
| ... | @@ -134,7 +135,7 @@ public final class ImmutableByteSequence { | ... | @@ -134,7 +135,7 @@ public final class ImmutableByteSequence { |
| 134 | * Creates a new byte sequence of 1 byte containing the given value. | 135 | * Creates a new byte sequence of 1 byte containing the given value. |
| 135 | * | 136 | * |
| 136 | * @param original a byte value | 137 | * @param original a byte value |
| 137 | - * @return a new immutable byte buffer | 138 | + * @return a new immutable byte sequence |
| 138 | */ | 139 | */ |
| 139 | public static ImmutableByteSequence copyFrom(byte original) { | 140 | public static ImmutableByteSequence copyFrom(byte original) { |
| 140 | return new ImmutableByteSequence( | 141 | return new ImmutableByteSequence( |
| ... | @@ -142,6 +143,30 @@ public final class ImmutableByteSequence { | ... | @@ -142,6 +143,30 @@ public final class ImmutableByteSequence { |
| 142 | } | 143 | } |
| 143 | 144 | ||
| 144 | /** | 145 | /** |
| 146 | + * Creates a new byte sequence of the given size where alla bits are 0. | ||
| 147 | + * | ||
| 148 | + * @param size number of bytes | ||
| 149 | + * @return a new immutable byte sequence | ||
| 150 | + */ | ||
| 151 | + public static ImmutableByteSequence ofZeros(int size) { | ||
| 152 | + byte[] bytes = new byte[size]; | ||
| 153 | + Arrays.fill(bytes, (byte) 0); | ||
| 154 | + return new ImmutableByteSequence(ByteBuffer.wrap(bytes)); | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + /** | ||
| 158 | + * Creates a new byte sequence of the given size where alla bits are 1. | ||
| 159 | + * | ||
| 160 | + * @param size number of bytes | ||
| 161 | + * @return a new immutable byte sequence | ||
| 162 | + */ | ||
| 163 | + public static ImmutableByteSequence ofOnes(int size) { | ||
| 164 | + byte[] bytes = new byte[size]; | ||
| 165 | + Arrays.fill(bytes, (byte) 0xFF); | ||
| 166 | + return new ImmutableByteSequence(ByteBuffer.wrap(bytes)); | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + /** | ||
| 145 | * Returns a view of this sequence as a read-only {@link ByteBuffer}. | 170 | * Returns a view of this sequence as a read-only {@link ByteBuffer}. |
| 146 | * <p> | 171 | * <p> |
| 147 | * The returned buffer will have position 0, while limit and capacity will | 172 | * The returned buffer will have position 0, while limit and capacity will | ... | ... |
-
Please register or login to post a comment