Hongtao Yin | 142b758 | 2015-01-21 14:41:30 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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.net.flowext; |
| 17 | |
| 18 | import java.nio.ByteBuffer; |
| 19 | import java.util.Objects; |
| 20 | |
| 21 | /** |
| 22 | * Experimental extension to the flow rule subsystem; still under development. |
| 23 | * Represents a generic abstraction of the service data. User app can customize whatever it needs to install on devices. |
| 24 | */ |
| 25 | public class DownStreamFlowEntry implements FlowEntryExtension { |
| 26 | |
| 27 | /** |
| 28 | * temporarily only have byte stream, but it will be extract more abstract information from it later. |
| 29 | */ |
| 30 | private final ByteBuffer payload; |
| 31 | |
| 32 | public DownStreamFlowEntry(ByteBuffer data) { |
| 33 | this.payload = data; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Get the payload of flowExtension. |
| 38 | * |
| 39 | * @return the byte steam value of payload. |
| 40 | */ |
| 41 | // @Override |
| 42 | // public ByteBuffer getPayload() { |
| 43 | // TODO Auto-generated method stub |
| 44 | // return payload; |
| 45 | // } |
| 46 | |
| 47 | /** |
| 48 | * Returns a hash code value for the object. |
| 49 | * It use payload as parameter to hash. |
| 50 | * |
| 51 | * @return a hash code value for this object. |
| 52 | */ |
| 53 | @Override |
| 54 | public int hashCode() { |
| 55 | return Objects.hash(payload); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Indicates whether some other object is "equal to" this one. |
| 60 | * |
| 61 | * @param obj the reference object with which to compare. |
| 62 | * @return {@code true} if this object is the same as the obj |
| 63 | * argument; {@code false} otherwise. |
| 64 | */ |
| 65 | @Override |
| 66 | public boolean equals(Object obj) { |
| 67 | if (obj instanceof DownStreamFlowEntry) { |
| 68 | DownStreamFlowEntry packet = (DownStreamFlowEntry) obj; |
| 69 | return Objects.equals(this.payload, packet.payload); |
| 70 | } else { |
| 71 | return false; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Returns a string representation of the object. |
| 77 | * |
| 78 | * @return a string representation of the object. |
| 79 | */ |
| 80 | @Override |
| 81 | public String toString() { |
| 82 | String obj = new String(payload.array()); |
| 83 | return obj; |
| 84 | } |
| 85 | } |