ONOS-506: IPv6 forwarding option for ReactiveForwarder.
org.onosproject.fwd.ReactiveForwarding.cfg ------------------------------------------ ipv6Forwarding = true will enable IPv6 forwarding in ReactiveForwarder. ONOS-506: Updates for the comment. * ReactiveForwarding.java Line 133: Make the comment to concrete Javadoc. Line 134: Method is changed to static. Line 141: Catch ClassCastException instead of generic Exception. * org.onosproject.fwd.ReactiveForwarding.cfg Line 3: Fix typo ;-). Line 7: Add comment: the option affects both IPv4 and IPv6. Change-Id: Ie7fdc7fc26c7d36b9633bfc828dffe27015214f7
Showing
2 changed files
with
68 additions
and
10 deletions
| ... | @@ -84,10 +84,15 @@ public class ReactiveForwarding { | ... | @@ -84,10 +84,15 @@ public class ReactiveForwarding { |
| 84 | label = "Enable packet-out only forwarding; default is false") | 84 | label = "Enable packet-out only forwarding; default is false") |
| 85 | private boolean packetOutOnly = false; | 85 | private boolean packetOutOnly = false; |
| 86 | 86 | ||
| 87 | + @Property(name = "ipv6Forwarding", boolValue = false, | ||
| 88 | + label = "Enable IPv6 forwarding; default is false") | ||
| 89 | + private boolean ipv6Forwarding = false; | ||
| 90 | + | ||
| 87 | @Activate | 91 | @Activate |
| 88 | - public void activate() { | 92 | + public void activate(ComponentContext context) { |
| 89 | appId = coreService.registerApplication("org.onosproject.fwd"); | 93 | appId = coreService.registerApplication("org.onosproject.fwd"); |
| 90 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); | 94 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); |
| 95 | + readComponentConfiguration(context); | ||
| 91 | log.info("Started with Application ID {}", appId.id()); | 96 | log.info("Started with Application ID {}", appId.id()); |
| 92 | } | 97 | } |
| 93 | 98 | ||
| ... | @@ -101,16 +106,49 @@ public class ReactiveForwarding { | ... | @@ -101,16 +106,49 @@ public class ReactiveForwarding { |
| 101 | 106 | ||
| 102 | @Modified | 107 | @Modified |
| 103 | public void modified(ComponentContext context) { | 108 | public void modified(ComponentContext context) { |
| 104 | - Dictionary properties = context.getProperties(); | 109 | + readComponentConfiguration(context); |
| 105 | - String flag = (String) properties.get("packetOutOnly"); | 110 | + } |
| 106 | - if (flag != null) { | 111 | + |
| 107 | - boolean enabled = flag.equals("true"); | 112 | + /** |
| 108 | - if (packetOutOnly != enabled) { | 113 | + * Extracts properties from the component configuration context. |
| 109 | - packetOutOnly = enabled; | 114 | + * |
| 110 | - log.info("Reconfigured. Packet-out only forwarding is {}", | 115 | + * @param context the component context |
| 116 | + */ | ||
| 117 | + private void readComponentConfiguration(ComponentContext context) { | ||
| 118 | + Dictionary<?, ?> properties = context.getProperties(); | ||
| 119 | + boolean packetOutOnlyEnabled = isPropertyEnabled(properties, "packetOutOnly"); | ||
| 120 | + if (packetOutOnly != packetOutOnlyEnabled) { | ||
| 121 | + packetOutOnly = packetOutOnlyEnabled; | ||
| 122 | + log.info("Configured. Packet-out only forwarding is {}", | ||
| 111 | packetOutOnly ? "enabled" : "disabled"); | 123 | packetOutOnly ? "enabled" : "disabled"); |
| 112 | } | 124 | } |
| 125 | + boolean ipv6ForwardingEnabled = isPropertyEnabled(properties, "ipv6Forwarding"); | ||
| 126 | + if (ipv6Forwarding != ipv6ForwardingEnabled) { | ||
| 127 | + ipv6Forwarding = ipv6ForwardingEnabled; | ||
| 128 | + log.info("Configured. IPv6 forwarding is {}", | ||
| 129 | + ipv6Forwarding ? "enabled" : "disabled"); | ||
| 130 | + } | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + /** | ||
| 134 | + * Check property name is defined and set to true. | ||
| 135 | + * | ||
| 136 | + * @param properties properties to be looked up | ||
| 137 | + * @param propertyName the name of the property to look up | ||
| 138 | + * @return true when the propertyName is defined and set to true | ||
| 139 | + */ | ||
| 140 | + private static boolean isPropertyEnabled(Dictionary<?, ?> properties, String propertyName) { | ||
| 141 | + boolean enabled = false; | ||
| 142 | + try { | ||
| 143 | + String flag = (String) properties.get(propertyName); | ||
| 144 | + if (flag != null) { | ||
| 145 | + enabled = flag.equals("true"); | ||
| 113 | } | 146 | } |
| 147 | + } catch (ClassCastException e) { | ||
| 148 | + // No propertyName defined. | ||
| 149 | + enabled = false; | ||
| 150 | + } | ||
| 151 | + return enabled; | ||
| 114 | } | 152 | } |
| 115 | 153 | ||
| 116 | /** | 154 | /** |
| ... | @@ -129,8 +167,13 @@ public class ReactiveForwarding { | ... | @@ -129,8 +167,13 @@ public class ReactiveForwarding { |
| 129 | InboundPacket pkt = context.inPacket(); | 167 | InboundPacket pkt = context.inPacket(); |
| 130 | Ethernet ethPkt = pkt.parsed(); | 168 | Ethernet ethPkt = pkt.parsed(); |
| 131 | 169 | ||
| 132 | - // Bail if this is deemed to be a control or IPv6 multicast packet. | 170 | + // Bail if this is deemed to be a control packet. |
| 133 | - if (isControlPacket(ethPkt) || isIpv6Multicast(ethPkt)) { | 171 | + if (isControlPacket(ethPkt)) { |
| 172 | + return; | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + // Skip IPv6 multicast packet when IPv6 forward is disabled. | ||
| 176 | + if (!ipv6Forwarding && isIpv6Multicast(ethPkt)) { | ||
| 134 | return; | 177 | return; |
| 135 | } | 178 | } |
| 136 | 179 | ... | ... |
| 1 | +# | ||
| 2 | +# Sample configuration for onos-app-fwd. | ||
| 3 | +# This configuration file would be placed at: $(KARAF_ROOT)/etc. | ||
| 4 | +# | ||
| 5 | + | ||
| 6 | +# | ||
| 7 | +# Enable packet-out only forwarding. | ||
| 8 | +# This flag affects to both IPv4 and IPv6. | ||
| 9 | +# | ||
| 10 | +# packetOutOnly = true | ||
| 11 | + | ||
| 12 | +# | ||
| 13 | +# Enable IPv6 forwarding. | ||
| 14 | +# | ||
| 15 | +# ipv6Forwarding = true |
-
Please register or login to post a comment