2 * Copyright (c) 2017 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
8 package org.opendaylight.lispflowmapping.lisp.util;
10 import java.util.List;
11 import java.util.Objects;
12 import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
19 * Utility class for MappingRecord objects.
21 * @author Lorand Jakab
24 public final class MappingRecordUtil {
25 protected static final Logger LOG = LoggerFactory.getLogger(MappingRecordUtil.class);
27 // Utility class, should not be instantiated
28 private MappingRecordUtil() {
31 public static boolean isNegativeMapping(MappingRecord mapping) {
32 List<LocatorRecord> rlocs = mapping.getLocatorRecord();
33 if (mapping.getAction() == LispMessage.NEGATIVE_MAPPING_ACTION && (rlocs == null || rlocs.isEmpty())) {
39 public static boolean isPositiveMapping(MappingRecord mapping) {
40 return !isNegativeMapping(mapping);
43 public static boolean mappingChanged(MappingRecord oldMapping, MappingRecord newMapping) {
44 if (LOG.isTraceEnabled()) {
45 LOG.trace("mappingChanged():\noldMapping = {}\nnewMapping = {}", oldMapping, newMapping);
47 // We only check for fields we care about
48 // XXX: This code needs to be checked and updated when the YANG model for MappingRecord is modified
49 if (oldMapping == null && newMapping == null) {
50 LOG.trace("mappingChanged(): FALSE");
52 } else if (oldMapping == null) {
53 LOG.trace("mappingChanged(): old mapping is null");
55 } else if (!Objects.equals(oldMapping.getEid(), newMapping.getEid())) {
56 LOG.trace("mappingChanged(): EID");
58 } else if (!Objects.equals(oldMapping.getLocatorRecord(), newMapping.getLocatorRecord())) {
59 LOG.trace("mappingChanged(): RLOC");
61 } else if (!Objects.equals(oldMapping.getAction(), newMapping.getAction())) {
62 LOG.trace("mappingChanged(): action");
64 } else if (!Objects.equals(oldMapping.getRecordTtl(), newMapping.getRecordTtl())) {
65 LOG.trace("mappingChanged(): TTL");
67 } else if (!Objects.equals(oldMapping.getMapVersion(), newMapping.getMapVersion())) {
68 LOG.trace("mappingChanged(): mapping version");
71 LOG.trace("mappingChanged(): FALSE");