2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. 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.netvirt.vpnmanager;
10 import java.net.InetAddress;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.concurrent.Callable;
14 import java.util.concurrent.DelayQueue;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 import com.google.common.util.concurrent.ListenableFuture;
22 public class ArpaddchacheTask implements Callable<List<ListenableFuture<Void>>> {
23 InetAddress srcInetAddr;
24 MacAddress srcMacAddress;
27 DelayQueue<MacEntry> macEntryQueue;
28 private static final Logger LOG = LoggerFactory.getLogger(ArpaddchacheTask.class);
30 public ArpaddchacheTask(InetAddress srcInetAddr, MacAddress srcMacAddress, String vpnName, String interfaceName,
31 DelayQueue<MacEntry> macEntryQueue) {
33 this.srcInetAddr = srcInetAddr;
34 this.srcMacAddress = srcMacAddress;
35 this.vpnName = vpnName;
36 this.interfaceName = interfaceName;
37 this.macEntryQueue = macEntryQueue;
43 public List<ListenableFuture<Void>> call() throws Exception {
44 List<ListenableFuture<Void>> futures = new ArrayList<>();
45 addOrUpdateMacEntryToQueue(vpnName,srcMacAddress, srcInetAddr, interfaceName);
49 public void addOrUpdateMacEntryToQueue(String vpnName, MacAddress macAddress,InetAddress InetAddress, String interfaceName) {
50 MacEntry newMacEntry = new MacEntry(ArpConstants.arpCacheTimeout,vpnName,macAddress, InetAddress,interfaceName );
51 if (!macEntryQueue.contains(newMacEntry)) {
52 LOG.info("Adding ARP cache");
53 macEntryQueue.offer(newMacEntry);
56 macEntryQueue.remove(newMacEntry);
57 macEntryQueue.offer(newMacEntry);