Migrate lisp-proto implementation to IETF YANG model
[lispflowmapping.git] / mappingservice / lisp-proto / src / main / java / org / opendaylight / lispflowmapping / lisp / util / MapNotifyBuilderHelper.java
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
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
16
17 public class MapNotifyBuilderHelper {
18
19     public static void setFromMapRegister(MapNotifyBuilder builder, MapRegister mapRegister) {
20         if (builder.getMappingRecordItem() == null) {
21             builder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
22         }
23         builder.setNonce(mapRegister.getNonce());
24         builder.setKeyId(mapRegister.getKeyId());
25         byte[] authenticationData = mapRegister.getAuthenticationData();
26         if (authenticationData != null) {
27             authenticationData = authenticationData.clone();
28             Arrays.fill(authenticationData, (byte) 0);
29         }
30         builder.setAuthenticationData(authenticationData);
31
32         for (MappingRecordItem eidToLocator : mapRegister.getMappingRecordItem()) {
33             builder.getMappingRecordItem().add(eidToLocator);
34         }
35     }
36 }