View Javadoc

1   /*
2    * Copyright (c) 2014 Contextream, Inc. and others.  All rights reserved.
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6    * and is available at http://www.eclipse.org/legal/epl-v10.html
7    */
8   package org.opendaylight.lispflowmapping.lisp.util;
9   
10  import java.util.ArrayList;
11  import java.util.Arrays;
12  import java.util.List;
13  
14  import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister;
15  import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder;
16  import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
17  
18  public final class MapNotifyBuilderHelper {
19      // Utility class, should not be instantiated
20      private MapNotifyBuilderHelper() {
21      }
22  
23      public static void setFromMapRegister(MapNotifyBuilder builder, MapRegister mapRegister) {
24          setNonRecordFields(builder, mapRegister);
25  
26          if (builder.getMappingRecordItem() == null) {
27              builder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
28          }
29  
30          for (MappingRecordItem eidToLocator : mapRegister.getMappingRecordItem()) {
31              builder.getMappingRecordItem().add(eidToLocator);
32          }
33      }
34  
35      public static void setFromMapRegisterAndMappingRecordItems(MapNotifyBuilder builder, MapRegister mapRegister,
36              List<MappingRecordItem> mappings) {
37          setNonRecordFields(builder, mapRegister);
38          builder.setMappingRecordItem(mappings);
39      }
40  
41      private static void setNonRecordFields(MapNotifyBuilder builder, MapRegister mapRegister) {
42          builder.setNonce(mapRegister.getNonce());
43          builder.setKeyId(mapRegister.getKeyId());
44          builder.setMergeEnabled(mapRegister.isMergeEnabled());
45  
46          byte[] authenticationData = mapRegister.getAuthenticationData();
47          if (authenticationData != null) {
48              authenticationData = authenticationData.clone();
49              Arrays.fill(authenticationData, (byte) 0);
50          }
51          builder.setAuthenticationData(authenticationData);
52      }
53  }