Update DAO API
[lispflowmapping.git] / mappingservice / lisp-proto / src / main / java / org / opendaylight / lispflowmapping / lisp / serializer / SerializerHelper.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc.  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
9 package org.opendaylight.lispflowmapping.lisp.serializer;
10
11 import org.opendaylight.lispflowmapping.lisp.util.LcafSourceDestHelper;
12 import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.LcafSegmentAddress;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.LcafSourceDestAddress;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.LispAFIAddress;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.LispIpv4Address;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev150820.LispIpv6Address;
18
19 /**
20  * @author Florin Coras
21  *
22  *         Helper class needed to fix masks of EIDs in southbound incoming LISP packets.
23  *
24  *         RFC6830 defines masks and EIDs as separate fields of larger, encompassing blocks of LISP messages. However
25  *         within LispFlowMapping masks are internal fields of EIDs. The method fixMask should be used in deserializers
26  *         to ensure that masks for deserialized EIDs reflect accordingly the mask field values carried in LISP
27  *         messages.
28  */
29
30 public class SerializerHelper {
31     public static LispAFIAddress fixMask(LispAFIAddress addr, short mask) {
32         if (addr instanceof LispIpv4Address || addr instanceof LispIpv6Address || addr instanceof LcafSegmentAddress) {
33            return MaskUtil.setMask(addr, mask);
34         } else if (addr instanceof LcafSourceDestAddress) {
35            return MaskUtil.setMaskSourceDest(addr, LcafSourceDestHelper.getSrcMask(addr),
36                     LcafSourceDestHelper.getDstMask(addr));
37         }
38         return addr;
39     }
40 }