Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Ipv4MatchArbitraryBitMaskBuilder ipv4MatchBuilder = new Ipv4MatchArbitraryBitMaskBuilder();
- makeHashingMatch(flowRuleData.hashingData.get(), ipv4MatchBuilder);
- // vvvvvvvvvvvv If this section is removed, some fields are null, but the errors go away vvvvvvvvvvvvv
- if (flowRuleData.matchedSrcIp.isPresent()) {
- Ipv4Prefix ipPrefix = flowRuleData.matchedSrcIp.get();
- Ipv4Address ipAddr = new Ipv4Address(ipPrefix.getValue().split("/")[0]);
- ipv4MatchBuilder.setIpv4SourceAddressNoMask(ipAddr);
- if (ipv4MatchBuilder.getIpv4SourceArbitraryBitmask() == null) {
- // Match the whole address
- ipv4MatchBuilder.setIpv4SourceArbitraryBitmask(new DottedQuad("255.255.255.255"));
- }
- }
- if (flowRuleData.matchedDestIp.isPresent()) {
- Ipv4Prefix ipPrefix = flowRuleData.matchedDestIp.get();
- Ipv4Address ipAddr = new Ipv4Address(ipPrefix.getValue().split("/")[0]);
- ipv4MatchBuilder.setIpv4DestinationAddressNoMask(ipAddr);
- if (ipv4MatchBuilder.getIpv4DestinationArbitraryBitmask() == null) {
- // Match the whole address
- ipv4MatchBuilder.setIpv4DestinationArbitraryBitmask(new DottedQuad("255.255.255.255"));
- }
- }
- // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatchBuilder.build())
- .setLayer3Match(ipv4MatchBuilder.build());
- ...
- Somewhere else
- ...
- // This method works as expected and does not appear to cause any bugs
- public static void makeHashingMatch(HashingRuleData hashingData, Ipv4MatchArbitraryBitMaskBuilder ipv4MatchBuilder)
- {
- int i = hashingData.i;
- if (hashingData.hashingMode.equals(HashingMode.SOURCE_ONLY)) {
- int significantBitsMask = (int) (Math.pow(2, hashingData.numberOfBits) - 1);
- ipv4MatchBuilder.setIpv4SourceAddressNoMask( new Ipv4Address("0.0.0." + String.valueOf(i)))
- .setIpv4SourceArbitraryBitmask( new DottedQuad( "0.0.0." + String.valueOf(significantBitsMask)));
- } else if (hashingData.hashingMode.equals(HashingMode.DESTINATION_ONLY)) {
- int significantBitsMask = (int) (Math.pow(2, hashingData.numberOfBits) - 1);
- ipv4MatchBuilder.setIpv4DestinationAddressNoMask( new Ipv4Address("0.0.0." + String.valueOf(i)))
- .setIpv4DestinationArbitraryBitmask( new DottedQuad( "0.0.0." + String.valueOf(significantBitsMask)));
- } else if (hashingData.hashingMode.equals(HashingMode.SOURCE_AND_DESTINATION)) {
- int indexRange = (int) Math.pow(2, hashingData.numberOfBits/2);
- int significantBitsMask = (int) (indexRange - 1);
- int srcIndex = i%indexRange;
- int destIndex = (i - srcIndex)/indexRange;
- ipv4MatchBuilder.setIpv4SourceAddressNoMask( new Ipv4Address("0.0.0." + String.valueOf(srcIndex)))
- .setIpv4SourceArbitraryBitmask( new DottedQuad( "0.0.0." + String.valueOf(significantBitsMask)))
- .setIpv4DestinationAddressNoMask( new Ipv4Address("0.0.0." + String.valueOf(destIndex)))
- .setIpv4DestinationArbitraryBitmask( new DottedQuad( "0.0.0." + String.valueOf(significantBitsMask)));
- } else {
- throw new RuntimeException("unexpected value for HashingMode");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement