@Test public void testCreateUpdate() throws Exception { List<SxpBindingFields> add = new ArrayList<>(), dell = new ArrayList<>(); dell.add(getBinding(10, "192.168.10.1/32")); dell.add(getBinding(30, "2000::1/128")); add.add(getBinding(10000, "192.168.0.1/32")); add.add(getBinding(20000, "2001::1/64")); add.add(getBinding(20000, "10.10.10.10/30")); add.add(getBinding(30000, "2002::1/128")); add.add(getBinding(40000, "11.11.11.0/29")); add.add(getBinding(65000, "172.168.1.0/28")); ByteBuf message = LegacyMessageFactory.createUpdate(dell, add, Version.Version1, null); byte[] result = new byte[] {0, 0, 0, 42, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, 4, -64, -88, 10, 1, 0, 0, 0, 1, 0, 0, 0, 14, -64, -88, 0, 1, 0, 0, 0, 1, 0, 0, 0, 2, 39, 16}; assertArrayEquals(result, toBytes(message)); message = LegacyMessageFactory.createUpdate(dell, add, Version.Version2, null); result = new byte[] {0, 0, 0, 100, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, 4, -64, -88, 10, 1, 0, 0, 0, 4, 0, 0, 0, 16, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 14, -64, -88, 0, 1, 0, 0, 0, 1, 0, 0, 0, 2, 39, 16, 0, 0, 0, 2, 0, 0, 0, 26, 32, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 2, 117, 48}; assertArrayEquals(result, toBytes(message)); message = LegacyMessageFactory.createUpdate(dell, add, Version.Version3, null); result = new byte[] {0, 0, 0, -20, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, 4, -64, -88, 10, 1, 0, 0, 0, 4, 0, 0, 0, 16, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 14, -64, -88, 0, 1, 0, 0, 0, 1, 0, 0, 0, 2, 39, 16, 0, 0, 0, 2, 0, 0, 0, 35, 32, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 64, 0, 0, 0, 1, 0, 0, 0, 2, 78, 32, 0, 0, 0, 1, 0, 0, 0, 23, 10, 10, 10, 10, 0, 0, 0, 2, 0, 0, 0, 1, 30, 0, 0, 0, 1, 0, 0, 0, 2, 78, 32, 0, 0, 0, 2, 0, 0, 0, 26, 32, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 2, 117, 48, 0, 0, 0, 1, 0, 0, 0, 23, 11, 11, 11, 0, 0, 0, 0, 2, 0, 0, 0, 1, 29, 0, 0, 0, 1, 0, 0, 0, 2, -100, 64, 0, 0, 0, 1, 0, 0, 0, 23, -84, -88, 1, 0, 0, 0, 0, 2, 0, 0, 0, 1, 28, 0, 0, 0, 1, 0, 0, 0, 2, -3, -24}; assertArrayEquals(result, toBytes(message)); }
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);  }