Committed by
Gerrit Code Review
ONOS-3345 Add processing about Instruction type Extention in
GroupModBuider. Change-Id: I1c99db1c3c1105924ee7c6e2da31daa02f5a1af4
Showing
2 changed files
with
88 additions
and
17 deletions
| ... | @@ -15,11 +15,25 @@ | ... | @@ -15,11 +15,25 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.provider.of.group.impl; | 16 | package org.onosproject.provider.of.group.impl; |
| 17 | 17 | ||
| 18 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 19 | + | ||
| 20 | +import java.util.ArrayList; | ||
| 21 | +import java.util.Collections; | ||
| 22 | +import java.util.LinkedList; | ||
| 23 | +import java.util.List; | ||
| 24 | +import java.util.Optional; | ||
| 25 | + | ||
| 18 | import org.onlab.packet.Ip4Address; | 26 | import org.onlab.packet.Ip4Address; |
| 19 | import org.onlab.packet.Ip6Address; | 27 | import org.onlab.packet.Ip6Address; |
| 20 | import org.onosproject.core.GroupId; | 28 | import org.onosproject.core.GroupId; |
| 29 | +import org.onosproject.net.DeviceId; | ||
| 21 | import org.onosproject.net.PortNumber; | 30 | import org.onosproject.net.PortNumber; |
| 31 | +import org.onosproject.net.driver.DefaultDriverData; | ||
| 32 | +import org.onosproject.net.driver.DefaultDriverHandler; | ||
| 33 | +import org.onosproject.net.driver.Driver; | ||
| 34 | +import org.onosproject.net.driver.DriverService; | ||
| 22 | import org.onosproject.net.flow.TrafficTreatment; | 35 | import org.onosproject.net.flow.TrafficTreatment; |
| 36 | +import org.onosproject.net.flow.instructions.ExtensionInstruction; | ||
| 23 | import org.onosproject.net.flow.instructions.Instruction; | 37 | import org.onosproject.net.flow.instructions.Instruction; |
| 24 | import org.onosproject.net.flow.instructions.Instructions; | 38 | import org.onosproject.net.flow.instructions.Instructions; |
| 25 | import org.onosproject.net.flow.instructions.L0ModificationInstruction; | 39 | import org.onosproject.net.flow.instructions.L0ModificationInstruction; |
| ... | @@ -28,6 +42,7 @@ import org.onosproject.net.flow.instructions.L3ModificationInstruction; | ... | @@ -28,6 +42,7 @@ import org.onosproject.net.flow.instructions.L3ModificationInstruction; |
| 28 | import org.onosproject.net.group.GroupBucket; | 42 | import org.onosproject.net.group.GroupBucket; |
| 29 | import org.onosproject.net.group.GroupBuckets; | 43 | import org.onosproject.net.group.GroupBuckets; |
| 30 | import org.onosproject.net.group.GroupDescription; | 44 | import org.onosproject.net.group.GroupDescription; |
| 45 | +import org.onosproject.openflow.controller.ExtensionInterpreter; | ||
| 31 | import org.projectfloodlight.openflow.protocol.OFBucket; | 46 | import org.projectfloodlight.openflow.protocol.OFBucket; |
| 32 | import org.projectfloodlight.openflow.protocol.OFFactory; | 47 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 33 | import org.projectfloodlight.openflow.protocol.OFGroupAdd; | 48 | import org.projectfloodlight.openflow.protocol.OFGroupAdd; |
| ... | @@ -52,14 +67,6 @@ import org.projectfloodlight.openflow.types.U32; | ... | @@ -52,14 +67,6 @@ import org.projectfloodlight.openflow.types.U32; |
| 52 | import org.projectfloodlight.openflow.types.VlanPcp; | 67 | import org.projectfloodlight.openflow.types.VlanPcp; |
| 53 | import org.slf4j.Logger; | 68 | import org.slf4j.Logger; |
| 54 | 69 | ||
| 55 | -import java.util.ArrayList; | ||
| 56 | -import java.util.Collections; | ||
| 57 | -import java.util.LinkedList; | ||
| 58 | -import java.util.List; | ||
| 59 | -import java.util.Optional; | ||
| 60 | - | ||
| 61 | -import static org.slf4j.LoggerFactory.getLogger; | ||
| 62 | - | ||
| 63 | /* | 70 | /* |
| 64 | * Builder for GroupMod. | 71 | * Builder for GroupMod. |
| 65 | */ | 72 | */ |
| ... | @@ -70,6 +77,7 @@ public final class GroupModBuilder { | ... | @@ -70,6 +77,7 @@ public final class GroupModBuilder { |
| 70 | private GroupDescription.Type type; | 77 | private GroupDescription.Type type; |
| 71 | private OFFactory factory; | 78 | private OFFactory factory; |
| 72 | private Long xid; | 79 | private Long xid; |
| 80 | + private Optional<DriverService> driverService; | ||
| 73 | 81 | ||
| 74 | private final Logger log = getLogger(getClass()); | 82 | private final Logger log = getLogger(getClass()); |
| 75 | 83 | ||
| ... | @@ -85,6 +93,16 @@ public final class GroupModBuilder { | ... | @@ -85,6 +93,16 @@ public final class GroupModBuilder { |
| 85 | this.xid = xid.orElse((long) 0); | 93 | this.xid = xid.orElse((long) 0); |
| 86 | } | 94 | } |
| 87 | 95 | ||
| 96 | + private GroupModBuilder(GroupBuckets buckets, GroupId groupId, | ||
| 97 | + GroupDescription.Type type, OFFactory factory, | ||
| 98 | + Optional<Long> xid, Optional<DriverService> driverService) { | ||
| 99 | + this.buckets = buckets; | ||
| 100 | + this.groupId = groupId; | ||
| 101 | + this.type = type; | ||
| 102 | + this.factory = factory; | ||
| 103 | + this.xid = xid.orElse((long) 0); | ||
| 104 | + this.driverService = driverService; | ||
| 105 | + } | ||
| 88 | /** | 106 | /** |
| 89 | * Creates a builder for GroupMod. | 107 | * Creates a builder for GroupMod. |
| 90 | * | 108 | * |
| ... | @@ -103,6 +121,24 @@ public final class GroupModBuilder { | ... | @@ -103,6 +121,24 @@ public final class GroupModBuilder { |
| 103 | } | 121 | } |
| 104 | 122 | ||
| 105 | /** | 123 | /** |
| 124 | + * Creates a builder for GroupMod. | ||
| 125 | + * | ||
| 126 | + * @param buckets GroupBuckets object | ||
| 127 | + * @param groupId Group Id to create | ||
| 128 | + * @param type Group type | ||
| 129 | + * @param factory OFFactory object | ||
| 130 | + * @param xid transaction ID | ||
| 131 | + * @param driverService driver Service | ||
| 132 | + * @return GroupModBuilder object | ||
| 133 | + */ | ||
| 134 | + public static GroupModBuilder builder(GroupBuckets buckets, GroupId groupId, | ||
| 135 | + GroupDescription.Type type, OFFactory factory, | ||
| 136 | + Optional<Long> xid, Optional<DriverService> driverService) { | ||
| 137 | + | ||
| 138 | + return new GroupModBuilder(buckets, groupId, type, factory, xid, driverService); | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + /** | ||
| 106 | * Builds the GroupAdd OF message. | 142 | * Builds the GroupAdd OF message. |
| 107 | * | 143 | * |
| 108 | * @return GroupAdd OF message | 144 | * @return GroupAdd OF message |
| ... | @@ -218,6 +254,12 @@ public final class GroupModBuilder { | ... | @@ -218,6 +254,12 @@ public final class GroupModBuilder { |
| 218 | .setGroup(OFGroup.of(grp.groupId().id())); | 254 | .setGroup(OFGroup.of(grp.groupId().id())); |
| 219 | actions.add(actgrp.build()); | 255 | actions.add(actgrp.build()); |
| 220 | break; | 256 | break; |
| 257 | + case EXTENSION: | ||
| 258 | + Instructions.ExtensionInstructionWrapper wrapper = | ||
| 259 | + (Instructions.ExtensionInstructionWrapper) i; | ||
| 260 | + actions.add(buildExtensionAction( | ||
| 261 | + wrapper.extensionInstruction(), wrapper.deviceId())); | ||
| 262 | + break; | ||
| 221 | default: | 263 | default: |
| 222 | log.warn("Instruction type {} not yet implemented.", i.type()); | 264 | log.warn("Instruction type {} not yet implemented.", i.type()); |
| 223 | } | 265 | } |
| ... | @@ -372,5 +414,21 @@ public final class GroupModBuilder { | ... | @@ -372,5 +414,21 @@ public final class GroupModBuilder { |
| 372 | } | 414 | } |
| 373 | return null; | 415 | return null; |
| 374 | } | 416 | } |
| 417 | + | ||
| 418 | + private OFAction buildExtensionAction(ExtensionInstruction i, DeviceId deviceId) { | ||
| 419 | + if (!driverService.isPresent()) { | ||
| 420 | + log.error("No driver service present"); | ||
| 421 | + return null; | ||
| 422 | + } | ||
| 423 | + Driver driver = driverService.get().getDriver(deviceId); | ||
| 424 | + if (driver.hasBehaviour(ExtensionInterpreter.class)) { | ||
| 425 | + DefaultDriverHandler handler = | ||
| 426 | + new DefaultDriverHandler(new DefaultDriverData(driver, deviceId)); | ||
| 427 | + ExtensionInterpreter interpreter = handler.behaviour(ExtensionInterpreter.class); | ||
| 428 | + return interpreter.mapInstruction(factory, i); | ||
| 429 | + } | ||
| 430 | + | ||
| 431 | + return null; | ||
| 432 | + } | ||
| 375 | } | 433 | } |
| 376 | 434 | ... | ... |
| ... | @@ -16,7 +16,12 @@ | ... | @@ -16,7 +16,12 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.provider.of.group.impl; | 17 | package org.onosproject.provider.of.group.impl; |
| 18 | 18 | ||
| 19 | -import com.google.common.collect.Maps; | 19 | +import static org.slf4j.LoggerFactory.getLogger; |
| 20 | + | ||
| 21 | +import java.util.Collection; | ||
| 22 | +import java.util.Map; | ||
| 23 | +import java.util.Optional; | ||
| 24 | +import java.util.concurrent.atomic.AtomicLong; | ||
| 20 | 25 | ||
| 21 | import org.apache.felix.scr.annotations.Activate; | 26 | import org.apache.felix.scr.annotations.Activate; |
| 22 | import org.apache.felix.scr.annotations.Component; | 27 | import org.apache.felix.scr.annotations.Component; |
| ... | @@ -26,6 +31,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; | ... | @@ -26,6 +31,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 26 | import org.onosproject.core.DefaultGroupId; | 31 | import org.onosproject.core.DefaultGroupId; |
| 27 | import org.onosproject.core.GroupId; | 32 | import org.onosproject.core.GroupId; |
| 28 | import org.onosproject.net.DeviceId; | 33 | import org.onosproject.net.DeviceId; |
| 34 | +import org.onosproject.net.driver.DriverService; | ||
| 29 | import org.onosproject.net.group.DefaultGroup; | 35 | import org.onosproject.net.group.DefaultGroup; |
| 30 | import org.onosproject.net.group.Group; | 36 | import org.onosproject.net.group.Group; |
| 31 | import org.onosproject.net.group.GroupBuckets; | 37 | import org.onosproject.net.group.GroupBuckets; |
| ... | @@ -60,12 +66,7 @@ import org.projectfloodlight.openflow.protocol.OFStatsType; | ... | @@ -60,12 +66,7 @@ import org.projectfloodlight.openflow.protocol.OFStatsType; |
| 60 | import org.projectfloodlight.openflow.protocol.OFVersion; | 66 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 61 | import org.slf4j.Logger; | 67 | import org.slf4j.Logger; |
| 62 | 68 | ||
| 63 | -import java.util.Collection; | 69 | +import com.google.common.collect.Maps; |
| 64 | -import java.util.Map; | ||
| 65 | -import java.util.Optional; | ||
| 66 | -import java.util.concurrent.atomic.AtomicLong; | ||
| 67 | - | ||
| 68 | -import static org.slf4j.LoggerFactory.getLogger; | ||
| 69 | 70 | ||
| 70 | /** | 71 | /** |
| 71 | * Provider which uses an OpenFlow controller to handle Group. | 72 | * Provider which uses an OpenFlow controller to handle Group. |
| ... | @@ -81,6 +82,9 @@ public class OpenFlowGroupProvider extends AbstractProvider implements GroupProv | ... | @@ -81,6 +82,9 @@ public class OpenFlowGroupProvider extends AbstractProvider implements GroupProv |
| 81 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 82 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 82 | protected GroupProviderRegistry providerRegistry; | 83 | protected GroupProviderRegistry providerRegistry; |
| 83 | 84 | ||
| 85 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 86 | + protected DriverService driverService; | ||
| 87 | + | ||
| 84 | private GroupProviderService providerService; | 88 | private GroupProviderService providerService; |
| 85 | 89 | ||
| 86 | static final int POLL_INTERVAL = 10; | 90 | static final int POLL_INTERVAL = 10; |
| ... | @@ -139,12 +143,21 @@ public class OpenFlowGroupProvider extends AbstractProvider implements GroupProv | ... | @@ -139,12 +143,21 @@ public class OpenFlowGroupProvider extends AbstractProvider implements GroupProv |
| 139 | return; | 143 | return; |
| 140 | } | 144 | } |
| 141 | final Long groupModXid = XID_COUNTER.getAndIncrement(); | 145 | final Long groupModXid = XID_COUNTER.getAndIncrement(); |
| 142 | - GroupModBuilder builder = | 146 | + GroupModBuilder builder = null; |
| 143 | - GroupModBuilder.builder(groupOperation.buckets(), | 147 | + if (driverService == null) { |
| 148 | + builder = GroupModBuilder.builder(groupOperation.buckets(), | ||
| 144 | groupOperation.groupId(), | 149 | groupOperation.groupId(), |
| 145 | groupOperation.groupType(), | 150 | groupOperation.groupType(), |
| 146 | sw.factory(), | 151 | sw.factory(), |
| 147 | Optional.of(groupModXid)); | 152 | Optional.of(groupModXid)); |
| 153 | + } else { | ||
| 154 | + builder = GroupModBuilder.builder(groupOperation.buckets(), | ||
| 155 | + groupOperation.groupId(), | ||
| 156 | + groupOperation.groupType(), | ||
| 157 | + sw.factory(), | ||
| 158 | + Optional.of(groupModXid), | ||
| 159 | + Optional.of(driverService)); | ||
| 160 | + } | ||
| 148 | OFGroupMod groupMod = null; | 161 | OFGroupMod groupMod = null; |
| 149 | switch (groupOperation.opType()) { | 162 | switch (groupOperation.opType()) { |
| 150 | case ADD: | 163 | case ADD: | ... | ... |
-
Please register or login to post a comment