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 * @author Lorand Jakab
22 public final class SourceDestKeyHelper {
23 // Utility class, should not be instantiated
24 private SourceDestKeyHelper() {
27 private final static Logger LOG = LoggerFactory.getLogger(SourceDestKeyHelper.class);
28 public static Eid getSrc(Eid eid) {
29 Address addr = eid.getAddress();
30 if (addr instanceof SourceDestKey) {
31 return LispAddressUtil.asEid(((SourceDestKey) addr).getSourceDestKey().getSource(),
32 eid.getVirtualNetworkId());
38 public static Eid getDst(Eid eid) {
39 Address addr = eid.getAddress();
40 if (addr instanceof SourceDestKey) {
41 return LispAddressUtil.asEid(((SourceDestKey) addr).getSourceDestKey().getDest(),
42 eid.getVirtualNetworkId());
48 public static Eid getSrcBinary(Eid eid) {
49 if (eid.getAddress() instanceof SourceDestKey) {
50 return LispAddressUtil.asBinaryEid(((SourceDestKey) eid.getAddress()).getSourceDestKey().getSource(),
51 eid.getVirtualNetworkId());
56 public static Eid getDstBinary(Eid eid) {
57 if (eid.getAddress() instanceof SourceDestKey) {
58 return LispAddressUtil.asBinaryEid(((SourceDestKey) eid.getAddress()).getSourceDestKey().getDest(),
59 eid.getVirtualNetworkId());
64 public static short getSrcMask(Eid eid) {
65 Address addr = eid.getAddress();
66 if (!isSrcDst(addr)) {
69 return MaskUtil.getMaskForAddress(((SourceDestKey)addr).getSourceDestKey().getSource());
72 public static short getDstMask(Eid eid) {
73 Address addr = eid.getAddress();
74 if (!isSrcDst(addr)) {
77 return MaskUtil.getMaskForAddress(((SourceDestKey)addr).getSourceDestKey().getDest());
80 private static boolean isSrcDst(Address addr) {
81 if (!(addr instanceof SourceDestKey)) {
82 LOG.warn("Address {} is not a valid SourceDest LCAF", addr);