Committed by
Gerrit Code Review
add flowrule to specific ip for userdata
Change-Id: Ia38af7556cc0e04c173f3c337a8dd17f49a20eba
Showing
4 changed files
with
69 additions
and
3 deletions
| ... | @@ -106,6 +106,7 @@ import org.onosproject.vtnrsc.FloatingIp; | ... | @@ -106,6 +106,7 @@ import org.onosproject.vtnrsc.FloatingIp; |
| 106 | import org.onosproject.vtnrsc.RouterInterface; | 106 | import org.onosproject.vtnrsc.RouterInterface; |
| 107 | import org.onosproject.vtnrsc.SecurityGroup; | 107 | import org.onosproject.vtnrsc.SecurityGroup; |
| 108 | import org.onosproject.vtnrsc.SegmentationId; | 108 | import org.onosproject.vtnrsc.SegmentationId; |
| 109 | +import org.onosproject.vtnrsc.Subnet; | ||
| 109 | import org.onosproject.vtnrsc.SubnetId; | 110 | import org.onosproject.vtnrsc.SubnetId; |
| 110 | import org.onosproject.vtnrsc.TenantId; | 111 | import org.onosproject.vtnrsc.TenantId; |
| 111 | import org.onosproject.vtnrsc.TenantNetwork; | 112 | import org.onosproject.vtnrsc.TenantNetwork; |
| ... | @@ -205,6 +206,7 @@ public class VtnManager implements VtnService { | ... | @@ -205,6 +206,7 @@ public class VtnManager implements VtnService { |
| 205 | private static final String EX_PORT_OF_DEVICE = "exPortOfDevice"; | 206 | private static final String EX_PORT_OF_DEVICE = "exPortOfDevice"; |
| 206 | private static final String EX_PORT_MAP = "exPortMap"; | 207 | private static final String EX_PORT_MAP = "exPortMap"; |
| 207 | private static final String DEFAULT_IP = "0.0.0.0"; | 208 | private static final String DEFAULT_IP = "0.0.0.0"; |
| 209 | + private static final String USERDATA_IP = "169.254.169.254"; | ||
| 208 | private static final int SUBNET_NUM = 2; | 210 | private static final int SUBNET_NUM = 2; |
| 209 | 211 | ||
| 210 | private EventuallyConsistentMap<VirtualPortId, VirtualPort> vPortStore; | 212 | private EventuallyConsistentMap<VirtualPortId, VirtualPort> vPortStore; |
| ... | @@ -557,7 +559,27 @@ public class VtnManager implements VtnService { | ... | @@ -557,7 +559,27 @@ public class VtnManager implements VtnService { |
| 557 | for (PortNumber p : localTunnelPorts) { | 559 | for (PortNumber p : localTunnelPorts) { |
| 558 | programGroupTable(deviceId, appId, p, devices, type); | 560 | programGroupTable(deviceId, appId, p, devices, type); |
| 559 | } | 561 | } |
| 560 | - | 562 | + Subnet subnet = subnetService.getSubnet(subnetId); |
| 563 | + String deviceOwner = virtualPort.deviceOwner(); | ||
| 564 | + if (deviceOwner != null) { | ||
| 565 | + if (deviceOwner.equalsIgnoreCase("network:dhcp")) { | ||
| 566 | + Sets.newHashSet(devices).stream() | ||
| 567 | + .filter(d -> d.type() == Device.Type.SWITCH) | ||
| 568 | + .forEach(d -> { | ||
| 569 | + if (subnet != null) { | ||
| 570 | + IpAddress dstIp = IpAddress | ||
| 571 | + .valueOf(USERDATA_IP); | ||
| 572 | + classifierService | ||
| 573 | + .programUserdataClassifierRules(d.id(), | ||
| 574 | + subnet.cidr(), | ||
| 575 | + dstIp, | ||
| 576 | + mac, | ||
| 577 | + segmentationId, | ||
| 578 | + type); | ||
| 579 | + } | ||
| 580 | + }); | ||
| 581 | + } | ||
| 582 | + } | ||
| 561 | if (type == Objective.Operation.ADD) { | 583 | if (type == Objective.Operation.ADD) { |
| 562 | vPortStore.put(virtualPortId, virtualPort); | 584 | vPortStore.put(virtualPortId, virtualPort); |
| 563 | if (networkOflocalHostPorts == null) { | 585 | if (networkOflocalHostPorts == null) { | ... | ... |
| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | package org.onosproject.vtn.table; | 16 | package org.onosproject.vtn.table; |
| 17 | 17 | ||
| 18 | import org.onlab.packet.IpAddress; | 18 | import org.onlab.packet.IpAddress; |
| 19 | +import org.onlab.packet.IpPrefix; | ||
| 19 | import org.onlab.packet.MacAddress; | 20 | import org.onlab.packet.MacAddress; |
| 20 | import org.onosproject.core.ApplicationId; | 21 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.net.DeviceId; | 22 | import org.onosproject.net.DeviceId; |
| ... | @@ -102,4 +103,20 @@ public interface ClassifierService { | ... | @@ -102,4 +103,20 @@ public interface ClassifierService { |
| 102 | SegmentationId actionVni, | 103 | SegmentationId actionVni, |
| 103 | Objective.Operation type); | 104 | Objective.Operation type); |
| 104 | 105 | ||
| 106 | + /** | ||
| 107 | + * Assemble the Userdata Classifier table rules. | ||
| 108 | + * Match: subnet ip prefix and destination ip. | ||
| 109 | + * Action: add flow rule to specific ip for userdata. | ||
| 110 | + * | ||
| 111 | + * @param deviceId Device Id | ||
| 112 | + * @param ipPrefix source ip prefix | ||
| 113 | + * @param dstIp userdata ip | ||
| 114 | + * @param dstmac dst mac | ||
| 115 | + * @param actionVni the vni of the source network (l2vni) | ||
| 116 | + * @param type the operation type of the flow rules | ||
| 117 | + */ | ||
| 118 | + void programUserdataClassifierRules(DeviceId deviceId, IpPrefix ipPrefix, | ||
| 119 | + IpAddress dstIp, MacAddress dstmac, | ||
| 120 | + SegmentationId actionVni, | ||
| 121 | + Objective.Operation type); | ||
| 105 | } | 122 | } | ... | ... |
| ... | @@ -56,7 +56,7 @@ public class ClassifierServiceImpl implements ClassifierService { | ... | @@ -56,7 +56,7 @@ public class ClassifierServiceImpl implements ClassifierService { |
| 56 | private static final int ARP_CLASSIFIER_PRIORITY = 60000; | 56 | private static final int ARP_CLASSIFIER_PRIORITY = 60000; |
| 57 | private static final int L3_CLASSIFIER_PRIORITY = 0xffff; | 57 | private static final int L3_CLASSIFIER_PRIORITY = 0xffff; |
| 58 | private static final int L2_CLASSIFIER_PRIORITY = 50000; | 58 | private static final int L2_CLASSIFIER_PRIORITY = 50000; |
| 59 | - | 59 | + private static final int USERDATA_CLASSIFIER_PRIORITY = 65535; |
| 60 | private final FlowObjectiveService flowObjectiveService; | 60 | private final FlowObjectiveService flowObjectiveService; |
| 61 | private final ApplicationId appId; | 61 | private final ApplicationId appId; |
| 62 | 62 | ||
| ... | @@ -193,4 +193,29 @@ public class ClassifierServiceImpl implements ClassifierService { | ... | @@ -193,4 +193,29 @@ public class ClassifierServiceImpl implements ClassifierService { |
| 193 | } | 193 | } |
| 194 | } | 194 | } |
| 195 | 195 | ||
| 196 | + @Override | ||
| 197 | + public void programUserdataClassifierRules(DeviceId deviceId, | ||
| 198 | + IpPrefix ipPrefix, | ||
| 199 | + IpAddress dstIp, | ||
| 200 | + MacAddress dstmac, | ||
| 201 | + SegmentationId actionVni, | ||
| 202 | + Objective.Operation type) { | ||
| 203 | + TrafficSelector selector = DefaultTrafficSelector.builder() | ||
| 204 | + .matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(ipPrefix) | ||
| 205 | + .matchIPDst(IpPrefix.valueOf(dstIp, 32)).build(); | ||
| 206 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder() | ||
| 207 | + .setTunnelId(Long.parseLong(actionVni.segmentationId())) | ||
| 208 | + .setEthDst(dstmac).build(); | ||
| 209 | + ForwardingObjective.Builder objective = DefaultForwardingObjective | ||
| 210 | + .builder().withTreatment(treatment).withSelector(selector) | ||
| 211 | + .fromApp(appId).withFlag(Flag.SPECIFIC) | ||
| 212 | + .withPriority(USERDATA_CLASSIFIER_PRIORITY); | ||
| 213 | + if (type.equals(Objective.Operation.ADD)) { | ||
| 214 | + log.debug("UserdataClassifierRules-->ADD"); | ||
| 215 | + flowObjectiveService.forward(deviceId, objective.add()); | ||
| 216 | + } else { | ||
| 217 | + log.debug("UserdataClassifierRules-->REMOVE"); | ||
| 218 | + flowObjectiveService.forward(deviceId, objective.remove()); | ||
| 219 | + } | ||
| 220 | + } | ||
| 196 | } | 221 | } | ... | ... |
| ... | @@ -51,6 +51,7 @@ import org.onosproject.vtnrsc.PortPair; | ... | @@ -51,6 +51,7 @@ import org.onosproject.vtnrsc.PortPair; |
| 51 | import org.onosproject.vtnrsc.PortPairGroup; | 51 | import org.onosproject.vtnrsc.PortPairGroup; |
| 52 | import org.onosproject.vtnrsc.PortPairId; | 52 | import org.onosproject.vtnrsc.PortPairId; |
| 53 | import org.onosproject.vtnrsc.Router; | 53 | import org.onosproject.vtnrsc.Router; |
| 54 | +import org.onosproject.vtnrsc.RouterId; | ||
| 54 | import org.onosproject.vtnrsc.RouterInterface; | 55 | import org.onosproject.vtnrsc.RouterInterface; |
| 55 | import org.onosproject.vtnrsc.SegmentationId; | 56 | import org.onosproject.vtnrsc.SegmentationId; |
| 56 | import org.onosproject.vtnrsc.Subnet; | 57 | import org.onosproject.vtnrsc.Subnet; |
| ... | @@ -167,7 +168,8 @@ public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscLi | ... | @@ -167,7 +168,8 @@ public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscLi |
| 167 | 168 | ||
| 168 | KryoNamespace.Builder serializer = KryoNamespace.newBuilder() | 169 | KryoNamespace.Builder serializer = KryoNamespace.newBuilder() |
| 169 | .register(KryoNamespaces.API) | 170 | .register(KryoNamespaces.API) |
| 170 | - .register(TenantId.class, DeviceId.class, SegmentationId.class); | 171 | + .register(TenantId.class, DeviceId.class, SegmentationId.class, |
| 172 | + TenantRouter.class, RouterId.class); | ||
| 171 | l3vniTenantMap = storageService | 173 | l3vniTenantMap = storageService |
| 172 | .<TenantId, SegmentationId>eventuallyConsistentMapBuilder() | 174 | .<TenantId, SegmentationId>eventuallyConsistentMapBuilder() |
| 173 | .withName(L3VNITENANTMAP).withSerializer(serializer) | 175 | .withName(L3VNITENANTMAP).withSerializer(serializer) | ... | ... |
-
Please register or login to post a comment