blob: 721cced719f4c41be9c7b85f0cf41c09058f2464 [file] [log] [blame]
Hongtao Yin142b7582015-01-21 14:41:30 -08001/*
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 */
16package org.onosproject.net.flowext;
17
18import org.onosproject.core.ApplicationId;
19import org.onosproject.core.DefaultGroupId;
20import org.onosproject.core.GroupId;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.flow.DefaultFlowRule;
23import org.onosproject.net.flow.FlowRule;
24import org.onosproject.net.flow.TrafficSelector;
25import org.onosproject.net.flow.TrafficTreatment;
26
27import java.util.Objects;
28
29import static com.google.common.base.MoreObjects.toStringHelper;
30
31/**
32 * Experimental extension to the flow rule subsystem; still under development.
33 * A temporary flow rule extend implementation, It will cover current onos flow rule and other flow extension.
34 */
35public class DefaultFlowRuleExt
36 extends DefaultFlowRule implements FlowRuleExt {
37
38 private FlowEntryExtension flowEntryExtension;
39
40 public DefaultFlowRuleExt(DeviceId deviceId, TrafficSelector selector,
41 TrafficTreatment treatment, int priority, long flowId,
42 int timeout, boolean permanent) {
43 super(deviceId, selector, treatment, priority, flowId, timeout, permanent);
44 }
45
46 public DefaultFlowRuleExt(DeviceId deviceId, TrafficSelector selector,
47 TrafficTreatment treatment, int priority, ApplicationId appId,
48 int timeout, boolean permanent) {
49 this(deviceId, selector, treatment, priority, appId, new DefaultGroupId(0),
50 timeout, permanent);
51 }
52
53 public DefaultFlowRuleExt(DeviceId deviceId, TrafficSelector selector,
54 TrafficTreatment treatment, int priority, ApplicationId appId,
55 GroupId groupId, int timeout, boolean permanent) {
56 super(deviceId, selector, treatment, priority, appId, groupId, timeout, permanent);
57 }
58
59 public DefaultFlowRuleExt(FlowRule rule) {
60 super(rule);
61 }
62
63 public DefaultFlowRuleExt(ApplicationId appId, DeviceId deviceId, FlowEntryExtension data) {
64 this(deviceId, null, null, FlowRule.MIN_PRIORITY, appId, 0, false);
65 this.flowEntryExtension = data;
66 }
67
68 @Override
69 public FlowEntryExtension getFlowEntryExt() {
70 return this.flowEntryExtension;
71 }
72
73 @Override
74 public int hashCode() {
75 return 31 * super.hashCode() + Objects.hash(flowEntryExtension);
76 }
77
78 public int hash() {
79 return 31 * super.hashCode() + Objects.hash(flowEntryExtension);
80 }
81
82 @Override
83 public boolean equals(Object obj) {
84 if (this == obj) {
85 return true;
86 }
87 if (obj == null || getClass() != obj.getClass()) {
88 return false;
89 }
90 if (!super.equals(obj)) {
91 return false;
92 }
93 final DefaultFlowRuleExt other = (DefaultFlowRuleExt) obj;
94 return Objects.equals(this.flowEntryExtension, other.flowEntryExtension);
95 }
96
97 @Override
98 public String toString() {
99 return toStringHelper(this)
100 // TODO there might be a better way to grab super's string
101 .add("id", Long.toHexString(id().value()))
102 .add("deviceId", deviceId())
103 .add("priority", priority())
104 .add("selector", selector().criteria())
105 .add("treatment", treatment() == null ? "N/A" : treatment().instructions())
106 //.add("created", created)
107 .add("flowEntryExtension", flowEntryExtension)
108 .toString();
109 }
110}