Upstreaming changes in netvirt
[netvirt.git] / vpnservice / vpnmanager / vpnmanager-impl / src / main / java / org / opendaylight / netvirt / vpnmanager / ArpaddchacheTask.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. 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 package org.opendaylight.netvirt.vpnmanager;
9
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;
15
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;
19
20 import com.google.common.util.concurrent.ListenableFuture;
21
22 public class ArpaddchacheTask implements Callable<List<ListenableFuture<Void>>> {
23     InetAddress srcInetAddr;
24     MacAddress srcMacAddress;
25     String vpnName;
26     String interfaceName;
27     DelayQueue<MacEntry> macEntryQueue;
28     private static final Logger LOG = LoggerFactory.getLogger(ArpaddchacheTask.class);
29
30     public ArpaddchacheTask(InetAddress srcInetAddr, MacAddress srcMacAddress, String vpnName, String interfaceName,
31                             DelayQueue<MacEntry> macEntryQueue) {
32         super();
33         this.srcInetAddr = srcInetAddr;
34         this.srcMacAddress = srcMacAddress;
35         this.vpnName = vpnName;
36         this.interfaceName = interfaceName;
37         this.macEntryQueue = macEntryQueue;
38     }
39
40
41
42     @Override
43     public List<ListenableFuture<Void>> call() throws Exception {
44         List<ListenableFuture<Void>> futures = new ArrayList<>();
45         addOrUpdateMacEntryToQueue(vpnName,srcMacAddress, srcInetAddr, interfaceName);
46         return futures;
47     }
48
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);
54         }
55         else{
56             macEntryQueue.remove(newMacEntry);
57             macEntryQueue.offer(newMacEntry);
58         }
59     }
60 }