Shashikanth VH | 8b1a5ef | 2016-12-26 14:37:43 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-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 | package org.onosproject.driver.flowspec.extensions; |
| 17 | |
| 18 | import org.onlab.util.KryoNamespace; |
| 19 | import org.onosproject.flowapi.ExtFlowContainer; |
| 20 | import org.onosproject.net.flow.AbstractExtension; |
| 21 | import org.onosproject.net.flow.criteria.ExtensionSelector; |
| 22 | import org.onosproject.net.flow.criteria.ExtensionSelectorType; |
| 23 | |
| 24 | import java.util.Objects; |
| 25 | |
| 26 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 27 | |
| 28 | /** |
| 29 | * Implementation of extension selector for multi value. |
| 30 | */ |
| 31 | public final class ExtMatchExtension extends AbstractExtension implements ExtensionSelector { |
| 32 | private ExtFlowContainer container; |
| 33 | private final KryoNamespace appKryo = new KryoNamespace.Builder().register(ExtMatchExtension.class).build(); |
| 34 | |
| 35 | /** |
| 36 | * Creates an object of ExtMatchExtension. |
| 37 | */ |
| 38 | public ExtMatchExtension() { |
| 39 | this.container = null; |
| 40 | } |
| 41 | /** |
| 42 | * Returns the container. |
| 43 | * |
| 44 | * @return the container to match |
| 45 | */ |
| 46 | public ExtFlowContainer container() { |
| 47 | return container; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public ExtensionSelectorType type() { |
| 52 | return ExtensionSelectorType.ExtensionSelectorTypes.EXT_MATCH_FLOW_TYPE.type(); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public byte[] serialize() { |
| 57 | return appKryo.serialize(container); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public void deserialize(byte[] data) { |
| 62 | container = ExtFlowContainer.of(appKryo.deserialize(data)); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public String toString() { |
| 67 | return toStringHelper(type().toString()) |
| 68 | .add("container", container) |
| 69 | .toString(); |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public int hashCode() { |
| 74 | return Objects.hash(type(), container); |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public boolean equals(Object obj) { |
| 79 | if (this == obj) { |
| 80 | return true; |
| 81 | } |
| 82 | if (obj instanceof ExtMatchExtension) { |
| 83 | ExtMatchExtension that = (ExtMatchExtension) obj; |
| 84 | return Objects.equals(container, that.container) && |
| 85 | Objects.equals(this.type(), that.type()); |
| 86 | } |
| 87 | return false; |
| 88 | } |
| 89 | } |