@Test(expected = UnknownVersionException.class) public void testCreateUpdateWithNonLegacyInput() { LegacyMessageFactory.createUpdate(null, null, Version.Version4, null); }
public static <T extends SxpBindingFields> ByteBuf createUpdate(List<T> deleteBindings, List<T> addBindings, Version version, SxpBindingFilter bindingFilter) { if (version == null || !MessageFactory.isLegacy(version)) { throw new UnknownVersionException(); } MappingRecordList mappingRecords = new MappingRecordList(); if (deleteBindings != null && !deleteBindings.isEmpty()) { deleteBindings.forEach(binding -> { switch (version) { case Version3: if (binding.getIpPrefix().getIpv4Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv4(binding.getIpPrefix())); } else if (binding.getIpPrefix().getIpv6Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv6(binding.getIpPrefix())); } break; case Version2: if (binding.getIpPrefix().getIpv6Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 128) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv6(binding.getIpPrefix())); } break; } case Version1: if (binding.getIpPrefix().getIpv4Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 32) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv4(binding.getIpPrefix())); } } break; } }); } if (addBindings != null && !addBindings.isEmpty()) { addBindings.forEach(binding -> { if (bindingFilter != null && bindingFilter.apply(binding)) { return; } switch (version) { case Version3: if (binding.getIpPrefix().getIpv4Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createAddIpv4(binding.getSecurityGroupTag(), binding.getIpPrefix())); } else if (binding.getIpPrefix().getIpv6Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createAddIpv6(binding.getSecurityGroupTag(), binding.getIpPrefix())); } break; case Version2: if (binding.getIpPrefix().getIpv6Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 128) { mappingRecords.add(LegacyAttributeFactory.createAddIpv6(binding.getSecurityGroupTag(), binding.getIpPrefix())); } break; } case Version1: if (binding.getIpPrefix().getIpv4Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 32) { mappingRecords.add(LegacyAttributeFactory.createAddIpv4(binding.getSecurityGroupTag(), binding.getIpPrefix())); } } break; } }); } return getMessage(MessageType.Update, mappingRecords.toBytes()); }
LegacyMessageFactory extends MessageFactory { public static <T extends SxpBindingFields> ByteBuf createUpdate(List<T> deleteBindings, List<T> addBindings, Version version, SxpBindingFilter bindingFilter) { if (version == null || !MessageFactory.isLegacy(version)) { throw new UnknownVersionException(); } MappingRecordList mappingRecords = new MappingRecordList(); if (deleteBindings != null && !deleteBindings.isEmpty()) { deleteBindings.forEach(binding -> { switch (version) { case Version3: if (binding.getIpPrefix().getIpv4Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv4(binding.getIpPrefix())); } else if (binding.getIpPrefix().getIpv6Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv6(binding.getIpPrefix())); } break; case Version2: if (binding.getIpPrefix().getIpv6Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 128) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv6(binding.getIpPrefix())); } break; } case Version1: if (binding.getIpPrefix().getIpv4Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 32) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv4(binding.getIpPrefix())); } } break; } }); } if (addBindings != null && !addBindings.isEmpty()) { addBindings.forEach(binding -> { if (bindingFilter != null && bindingFilter.apply(binding)) { return; } switch (version) { case Version3: if (binding.getIpPrefix().getIpv4Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createAddIpv4(binding.getSecurityGroupTag(), binding.getIpPrefix())); } else if (binding.getIpPrefix().getIpv6Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createAddIpv6(binding.getSecurityGroupTag(), binding.getIpPrefix())); } break; case Version2: if (binding.getIpPrefix().getIpv6Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 128) { mappingRecords.add(LegacyAttributeFactory.createAddIpv6(binding.getSecurityGroupTag(), binding.getIpPrefix())); } break; } case Version1: if (binding.getIpPrefix().getIpv4Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 32) { mappingRecords.add(LegacyAttributeFactory.createAddIpv4(binding.getSecurityGroupTag(), binding.getIpPrefix())); } } break; } }); } return getMessage(MessageType.Update, mappingRecords.toBytes()); } }
LegacyMessageFactory extends MessageFactory { public static <T extends SxpBindingFields> ByteBuf createUpdate(List<T> deleteBindings, List<T> addBindings, Version version, SxpBindingFilter bindingFilter) { if (version == null || !MessageFactory.isLegacy(version)) { throw new UnknownVersionException(); } MappingRecordList mappingRecords = new MappingRecordList(); if (deleteBindings != null && !deleteBindings.isEmpty()) { deleteBindings.forEach(binding -> { switch (version) { case Version3: if (binding.getIpPrefix().getIpv4Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv4(binding.getIpPrefix())); } else if (binding.getIpPrefix().getIpv6Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv6(binding.getIpPrefix())); } break; case Version2: if (binding.getIpPrefix().getIpv6Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 128) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv6(binding.getIpPrefix())); } break; } case Version1: if (binding.getIpPrefix().getIpv4Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 32) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv4(binding.getIpPrefix())); } } break; } }); } if (addBindings != null && !addBindings.isEmpty()) { addBindings.forEach(binding -> { if (bindingFilter != null && bindingFilter.apply(binding)) { return; } switch (version) { case Version3: if (binding.getIpPrefix().getIpv4Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createAddIpv4(binding.getSecurityGroupTag(), binding.getIpPrefix())); } else if (binding.getIpPrefix().getIpv6Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createAddIpv6(binding.getSecurityGroupTag(), binding.getIpPrefix())); } break; case Version2: if (binding.getIpPrefix().getIpv6Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 128) { mappingRecords.add(LegacyAttributeFactory.createAddIpv6(binding.getSecurityGroupTag(), binding.getIpPrefix())); } break; } case Version1: if (binding.getIpPrefix().getIpv4Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 32) { mappingRecords.add(LegacyAttributeFactory.createAddIpv4(binding.getSecurityGroupTag(), binding.getIpPrefix())); } } break; } }); } return getMessage(MessageType.Update, mappingRecords.toBytes()); }  }
LegacyMessageFactory extends MessageFactory { public static <T extends SxpBindingFields> ByteBuf createUpdate(List<T> deleteBindings, List<T> addBindings, Version version, SxpBindingFilter bindingFilter) { if (version == null || !MessageFactory.isLegacy(version)) { throw new UnknownVersionException(); } MappingRecordList mappingRecords = new MappingRecordList(); if (deleteBindings != null && !deleteBindings.isEmpty()) { deleteBindings.forEach(binding -> { switch (version) { case Version3: if (binding.getIpPrefix().getIpv4Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv4(binding.getIpPrefix())); } else if (binding.getIpPrefix().getIpv6Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv6(binding.getIpPrefix())); } break; case Version2: if (binding.getIpPrefix().getIpv6Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 128) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv6(binding.getIpPrefix())); } break; } case Version1: if (binding.getIpPrefix().getIpv4Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 32) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv4(binding.getIpPrefix())); } } break; } }); } if (addBindings != null && !addBindings.isEmpty()) { addBindings.forEach(binding -> { if (bindingFilter != null && bindingFilter.apply(binding)) { return; } switch (version) { case Version3: if (binding.getIpPrefix().getIpv4Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createAddIpv4(binding.getSecurityGroupTag(), binding.getIpPrefix())); } else if (binding.getIpPrefix().getIpv6Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createAddIpv6(binding.getSecurityGroupTag(), binding.getIpPrefix())); } break; case Version2: if (binding.getIpPrefix().getIpv6Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 128) { mappingRecords.add(LegacyAttributeFactory.createAddIpv6(binding.getSecurityGroupTag(), binding.getIpPrefix())); } break; } case Version1: if (binding.getIpPrefix().getIpv4Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 32) { mappingRecords.add(LegacyAttributeFactory.createAddIpv4(binding.getSecurityGroupTag(), binding.getIpPrefix())); } } break; } }); } return getMessage(MessageType.Update, mappingRecords.toBytes()); }  static ByteBuf createError(ErrorCodeNonExtended errorCode); static ByteBuf createError(ErrorCodeNonExtended errorCode, byte[] data); static ByteBuf createOpen(Version version, ConnectionMode nodeMode); static ByteBuf createOpenResp(Version version, ConnectionMode nodeMode); static ByteBuf createUpdate(List<T> deleteBindings, List<T> addBindings,
            Version version, SxpBindingFilter bindingFilter); static Notification decodeOpen(byte[] payload); static Notification decodeOpenResp(byte[] payload); static Notification decodeUpdate(byte[] payload); }
LegacyMessageFactory extends MessageFactory { public static <T extends SxpBindingFields> ByteBuf createUpdate(List<T> deleteBindings, List<T> addBindings, Version version, SxpBindingFilter bindingFilter) { if (version == null || !MessageFactory.isLegacy(version)) { throw new UnknownVersionException(); } MappingRecordList mappingRecords = new MappingRecordList(); if (deleteBindings != null && !deleteBindings.isEmpty()) { deleteBindings.forEach(binding -> { switch (version) { case Version3: if (binding.getIpPrefix().getIpv4Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv4(binding.getIpPrefix())); } else if (binding.getIpPrefix().getIpv6Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv6(binding.getIpPrefix())); } break; case Version2: if (binding.getIpPrefix().getIpv6Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 128) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv6(binding.getIpPrefix())); } break; } case Version1: if (binding.getIpPrefix().getIpv4Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 32) { mappingRecords.add(LegacyAttributeFactory.createDeleteIpv4(binding.getIpPrefix())); } } break; } }); } if (addBindings != null && !addBindings.isEmpty()) { addBindings.forEach(binding -> { if (bindingFilter != null && bindingFilter.apply(binding)) { return; } switch (version) { case Version3: if (binding.getIpPrefix().getIpv4Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createAddIpv4(binding.getSecurityGroupTag(), binding.getIpPrefix())); } else if (binding.getIpPrefix().getIpv6Prefix() != null) { mappingRecords.add(LegacyAttributeFactory.createAddIpv6(binding.getSecurityGroupTag(), binding.getIpPrefix())); } break; case Version2: if (binding.getIpPrefix().getIpv6Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 128) { mappingRecords.add(LegacyAttributeFactory.createAddIpv6(binding.getSecurityGroupTag(), binding.getIpPrefix())); } break; } case Version1: if (binding.getIpPrefix().getIpv4Prefix() != null) { if (IpPrefixConv.getPrefixLength(binding.getIpPrefix()) == 32) { mappingRecords.add(LegacyAttributeFactory.createAddIpv4(binding.getSecurityGroupTag(), binding.getIpPrefix())); } } break; } }); } return getMessage(MessageType.Update, mappingRecords.toBytes()); }  static ByteBuf createError(ErrorCodeNonExtended errorCode); static ByteBuf createError(ErrorCodeNonExtended errorCode, byte[] data); static ByteBuf createOpen(Version version, ConnectionMode nodeMode); static ByteBuf createOpenResp(Version version, ConnectionMode nodeMode); static ByteBuf createUpdate(List<T> deleteBindings, List<T> addBindings,
            Version version, SxpBindingFilter bindingFilter); static Notification decodeOpen(byte[] payload); static Notification decodeOpenResp(byte[] payload); static Notification decodeUpdate(byte[] payload);  }