Skip to content

Commit d572762

Browse files
committed
Add group rule service, purge flood rules, use group to handle ARP
Change-Id: If0db889d6ab28a4d36f433f16bf84241d2726045
1 parent b3dc1ca commit d572762

File tree

6 files changed

+302
-43
lines changed

6 files changed

+302
-43
lines changed

apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/Constants.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public enum VnicType {
6868
public static final String UNSUPPORTED_VENDOR = "unsupported_vendor";
6969

7070
public static final int PRIORITY_TUNNEL_TAG_RULE = 30000;
71-
public static final int PRIORITY_FLOATING_INTERNAL = 42000;
7271
public static final int PRIORITY_FLOATING_EXTERNAL = 41000;
7372
public static final int PRIORITY_STATEFUL_SNAT_RULE = 40500;
7473
public static final int PRIORITY_ICMP_RULE = 43000;
@@ -79,7 +78,6 @@ public enum VnicType {
7978
public static final int PRIORITY_SNAT_RULE = 26000;
8079
public static final int PRIORITY_SWITCHING_RULE = 30000;
8180
public static final int PRIORITY_FLAT_JUMP_UPSTREAM_RULE = 41000;
82-
public static final int PRIORITY_FLAT_JUMP_DOWNSTREAM_RULE = 41000;
8381
public static final int PRIORITY_FLAT_UPSTREAM_RULE = 41000;
8482
public static final int PRIORITY_FLAT_DOWNSTREAM_RULE = 42000;
8583
public static final int PRIORITY_DHCP_RULE = 42000;
@@ -90,11 +88,10 @@ public enum VnicType {
9088
public static final int PRIORITY_CT_RULE = 32000;
9189
public static final int PRIORITY_CT_DROP_RULE = 32500;
9290
public static final int PRIORITY_ARP_GATEWAY_RULE = 41000;
93-
public static final int PRIORITY_ARP_SUBNET_RULE = 40000;
9491
public static final int PRIORITY_ARP_CONTROL_RULE = 40000;
9592
public static final int PRIORITY_ARP_REPLY_RULE = 40000;
9693
public static final int PRIORITY_ARP_REQUEST_RULE = 40000;
97-
public static final int PRIORITY_ARP_FLOOD_RULE = 39000;
94+
public static final int PRIORITY_ARP_GROUP_RULE = 39000;
9895
public static final int PRIORITY_FORCED_ACL_RULE = 50000;
9996
public static final int PRIORITY_ICMP_PROBE_RULE = 50000;
10097

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright 2019-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+
package org.onosproject.openstacknetworking.api;
17+
18+
import org.onosproject.core.ApplicationId;
19+
import org.onosproject.net.DeviceId;
20+
import org.onosproject.net.group.GroupBucket;
21+
import org.onosproject.net.group.GroupDescription;
22+
23+
import java.util.List;
24+
25+
/**
26+
* Service for setting group rules.
27+
*/
28+
public interface OpenstackGroupRuleService {
29+
30+
/**
31+
* Configures the group table rule.
32+
*
33+
* @param appId application ID
34+
* @param deviceId device ID
35+
* @param groupId group ID
36+
* @param type group type
37+
* @param buckets a list of group buckets
38+
* @param install true for rule addition, false for rule removal
39+
*/
40+
void setRule(ApplicationId appId, DeviceId deviceId, int groupId,
41+
GroupDescription.Type type, List<GroupBucket> buckets, boolean install);
42+
43+
/**
44+
* Checks whether has the group in store with given device ID and group ID.
45+
*
46+
* @param deviceId device ID
47+
* @param groupId group ID
48+
* @return true if the group exists, false otherwise
49+
*/
50+
boolean hasGroup(DeviceId deviceId, int groupId);
51+
52+
/**
53+
* Configures buckets to the existing group.
54+
* With install flag true, this method will add buckets to existing buckets,
55+
* while with install flag false, this method will remove buckets from
56+
* existing buckets.
57+
*
58+
* @param appId application ID
59+
* @param deviceId device ID
60+
* @param groupId group ID
61+
* @param buckets a list of group buckets
62+
* @param install true for buckets addition, false for buckets removal
63+
*/
64+
void setBuckets(ApplicationId appId, DeviceId deviceId, int groupId,
65+
List<GroupBucket> buckets, boolean install);
66+
67+
/**
68+
* Configures buckets.
69+
*
70+
* @param appId application ID
71+
* @param deviceId device ID
72+
* @param groupId group ID
73+
* @param buckets a lit of group buckets
74+
*/
75+
void setBuckets(ApplicationId appId, DeviceId deviceId, int groupId,
76+
List<GroupBucket> buckets);
77+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright 2019-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+
package org.onosproject.openstacknetworking.impl;
17+
18+
import org.onosproject.core.ApplicationId;
19+
import org.onosproject.core.CoreService;
20+
import org.onosproject.net.DeviceId;
21+
import org.onosproject.net.group.DefaultGroupDescription;
22+
import org.onosproject.net.group.GroupBucket;
23+
import org.onosproject.net.group.GroupBuckets;
24+
import org.onosproject.net.group.GroupDescription;
25+
import org.onosproject.net.group.GroupService;
26+
import org.onosproject.openstacknetworking.api.OpenstackGroupRuleService;
27+
import org.osgi.service.component.annotations.Activate;
28+
import org.osgi.service.component.annotations.Component;
29+
import org.osgi.service.component.annotations.Deactivate;
30+
import org.osgi.service.component.annotations.Reference;
31+
import org.osgi.service.component.annotations.ReferenceCardinality;
32+
import org.slf4j.Logger;
33+
34+
import java.util.List;
35+
36+
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getGroupKey;
37+
import static org.slf4j.LoggerFactory.getLogger;
38+
39+
/**
40+
* Sets group table rules directly using GroupService.
41+
*/
42+
@Component(immediate = true, service = OpenstackGroupRuleService.class)
43+
public class OpenstackGroupRuleManager implements OpenstackGroupRuleService {
44+
45+
private final Logger log = getLogger(getClass());
46+
47+
@Reference(cardinality = ReferenceCardinality.MANDATORY)
48+
protected GroupService groupService;
49+
50+
@Reference(cardinality = ReferenceCardinality.MANDATORY)
51+
protected CoreService coreService;
52+
53+
@Activate
54+
protected void activate() {
55+
log.info("Started");
56+
}
57+
58+
@Deactivate
59+
protected void deactivate() {
60+
log.info("Stopped");
61+
}
62+
63+
@Override
64+
public void setRule(ApplicationId appId, DeviceId deviceId, int groupId,
65+
GroupDescription.Type type, List<GroupBucket> buckets,
66+
boolean install) {
67+
if (install) {
68+
GroupDescription groupDesc = new DefaultGroupDescription(deviceId,
69+
type, new GroupBuckets(buckets), getGroupKey(groupId), groupId, appId);
70+
groupService.addGroup(groupDesc);
71+
log.info("Adding group rule {}", groupId);
72+
} else {
73+
groupService.removeGroup(deviceId, getGroupKey(groupId), appId);
74+
log.info("Removing group rule {}", groupId);
75+
}
76+
}
77+
78+
@Override
79+
public boolean hasGroup(DeviceId deviceId, int groupId) {
80+
return groupService.getGroup(deviceId, getGroupKey(groupId)) != null;
81+
}
82+
83+
@Override
84+
public void setBuckets(ApplicationId appId, DeviceId deviceId,
85+
int groupId, List<GroupBucket> buckets, boolean install) {
86+
if (install) {
87+
groupService.addBucketsToGroup(deviceId, getGroupKey(groupId),
88+
new GroupBuckets(buckets), getGroupKey(groupId), appId);
89+
log.info("Adding buckets for group rule {}", groupId);
90+
} else {
91+
groupService.removeBucketsFromGroup(deviceId, getGroupKey(groupId),
92+
new GroupBuckets(buckets), getGroupKey(groupId), appId);
93+
log.info("Removing buckets for group rule {}", groupId);
94+
}
95+
}
96+
97+
@Override
98+
public void setBuckets(ApplicationId appId, DeviceId deviceId,
99+
int groupId, List<GroupBucket> buckets) {
100+
groupService.setBucketsForGroup(deviceId, getGroupKey(groupId),
101+
new GroupBuckets(buckets), getGroupKey(groupId), appId);
102+
}
103+
}

0 commit comments

Comments
 (0)