2 * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
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
9 package org.opendaylight.lispflowmapping.lisp.util;
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
18 * Helper methods for Source/Dest Key type LCAF addresses.
20 * @author Lorand Jakab
24 public final class SourceDestKeyHelper {
25 // Utility class, should not be instantiated
26 private SourceDestKeyHelper() {
29 private static final Logger LOG = LoggerFactory.getLogger(SourceDestKeyHelper.class);
31 public static Eid getSrc(Eid eid) {
32 Address addr = eid.getAddress();
33 if (addr instanceof SourceDestKey) {
34 return LispAddressUtil.asEid(((SourceDestKey) addr).getSourceDestKey().getSource(),
35 eid.getVirtualNetworkId());
41 public static Eid getDst(Eid eid) {
42 Address addr = eid.getAddress();
43 if (addr instanceof SourceDestKey) {
44 return LispAddressUtil.asEid(((SourceDestKey) addr).getSourceDestKey().getDest(),
45 eid.getVirtualNetworkId());
51 public static Eid getSrcBinary(Eid eid) {
52 if (eid.getAddress() instanceof SourceDestKey) {
53 return LispAddressUtil.asBinaryEid(((SourceDestKey) eid.getAddress()).getSourceDestKey().getSource(),
54 eid.getVirtualNetworkId());
59 public static Eid getDstBinary(Eid eid) {
60 if (eid.getAddress() instanceof SourceDestKey) {
61 return LispAddressUtil.asBinaryEid(((SourceDestKey) eid.getAddress()).getSourceDestKey().getDest(),
62 eid.getVirtualNetworkId());
67 public static short getSrcMask(Eid eid) {
68 Address addr = eid.getAddress();
69 if (!isSrcDst(addr)) {
72 return MaskUtil.getMaskForAddress(((SourceDestKey)addr).getSourceDestKey().getSource());
75 public static short getDstMask(Eid eid) {
76 Address addr = eid.getAddress();
77 if (!isSrcDst(addr)) {
80 return MaskUtil.getMaskForAddress(((SourceDestKey)addr).getSourceDestKey().getDest());
83 private static boolean isSrcDst(Address addr) {
84 if (!(addr instanceof SourceDestKey)) {
85 LOG.warn("Address {} is not a valid SourceDest LCAF", addr);