From b58ffec4cd28dff942abebebdba460626be6568d Mon Sep 17 00:00:00 2001 From: maheshnikam <55378196+nikam14@users.noreply.github.com> Date: Tue, 10 Oct 2023 10:52:05 +0530 Subject: [PATCH] [cleanup] Deleted file FakeDhcpSnooper.java and DhcpSnooper.java (#7672) * Delete DhcpSnooper.java * Delete FakeDhcpSnooper.java --- .../com/cloud/agent/dhcp/DhcpSnooper.java | 41 ----- .../com/cloud/agent/dhcp/FakeDhcpSnooper.java | 161 ------------------ 2 files changed, 202 deletions(-) delete mode 100644 agent/src/main/java/com/cloud/agent/dhcp/DhcpSnooper.java delete mode 100644 agent/src/main/java/com/cloud/agent/dhcp/FakeDhcpSnooper.java diff --git a/agent/src/main/java/com/cloud/agent/dhcp/DhcpSnooper.java b/agent/src/main/java/com/cloud/agent/dhcp/DhcpSnooper.java deleted file mode 100644 index 67718d50095..00000000000 --- a/agent/src/main/java/com/cloud/agent/dhcp/DhcpSnooper.java +++ /dev/null @@ -1,41 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.agent.dhcp; - -import java.net.InetAddress; -import java.util.List; -import java.util.Map; - -import com.cloud.utils.Pair; -import com.cloud.utils.component.Adapter; - -public interface DhcpSnooper extends Adapter { - - public InetAddress getIPAddr(String macAddr, String vmName); - - public InetAddress getDhcpServerIP(); - - public void cleanup(String macAddr, String vmName); - - public Map syncIpAddr(); - - @Override - public boolean stop(); - - public void initializeMacTable(List> macVmNameList); - -} diff --git a/agent/src/main/java/com/cloud/agent/dhcp/FakeDhcpSnooper.java b/agent/src/main/java/com/cloud/agent/dhcp/FakeDhcpSnooper.java deleted file mode 100644 index c42a5af814d..00000000000 --- a/agent/src/main/java/com/cloud/agent/dhcp/FakeDhcpSnooper.java +++ /dev/null @@ -1,161 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.agent.dhcp; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.List; -import java.util.Map; -import java.util.Queue; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; - -import javax.naming.ConfigurationException; - -import org.apache.log4j.Logger; - -import com.cloud.utils.Pair; -import com.cloud.utils.net.NetUtils; - -public class FakeDhcpSnooper implements DhcpSnooper { - private static final Logger s_logger = Logger.getLogger(FakeDhcpSnooper.class); - private Queue _ipAddresses = new ConcurrentLinkedQueue(); - private Map _macIpMap = new ConcurrentHashMap(); - private Map _vmIpMap = new ConcurrentHashMap(); - - @Override - public boolean configure(String name, Map params) throws ConfigurationException { - String guestIpRange = (String)params.get("guest.ip.range"); - if (guestIpRange != null) { - String[] guestIps = guestIpRange.split("-"); - if (guestIps.length == 2) { - long start = NetUtils.ip2Long(guestIps[0]); - long end = NetUtils.ip2Long(guestIps[1]); - while (start <= end) { - _ipAddresses.offer(NetUtils.long2Ip(start++)); - } - } - } - return true; - } - - @Override - public boolean start() { - return true; - } - - @Override - public String getName() { - return "FakeDhcpSnooper"; - } - - @Override - public InetAddress getIPAddr(String macAddr, String vmName) { - String ipAddr = _ipAddresses.poll(); - if (ipAddr == null) { - s_logger.warn("No ip addresses left in queue"); - return null; - } - try { - InetAddress inetAddr = InetAddress.getByName(ipAddr); - _macIpMap.put(macAddr.toLowerCase(), ipAddr); - _vmIpMap.put(vmName, inetAddr); - s_logger.info("Got ip address " + ipAddr + " for vm " + vmName + " mac=" + macAddr.toLowerCase()); - return inetAddr; - } catch (UnknownHostException e) { - s_logger.warn("Failed to get InetAddress for " + ipAddr); - return null; - } - } - - @Override - public void cleanup(String macAddr, String vmName) { - try { - if (macAddr == null) { - return; - } - InetAddress inetAddr = _vmIpMap.remove(vmName); - String ipAddr = inetAddr.getHostName(); - for (Map.Entry entry : _macIpMap.entrySet()) { - if (entry.getValue().equalsIgnoreCase(ipAddr)) { - macAddr = entry.getKey(); - break; - } - } - ipAddr = _macIpMap.remove(macAddr); - - s_logger.info("Cleaning up for mac address: " + macAddr + " ip=" + ipAddr + " inetAddr=" + inetAddr); - if (ipAddr != null) { - _ipAddresses.offer(ipAddr); - } - } catch (Exception e) { - s_logger.debug("Failed to cleanup: " + e.toString()); - } - } - - @Override - public Map syncIpAddr() { - return _vmIpMap; - } - - @Override - public boolean stop() { - return false; - } - - @Override - public void initializeMacTable(List> macVmNameList) { - - } - - @Override - public InetAddress getDhcpServerIP() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void setName(String name) { - // TODO Auto-generated method stub - - } - - @Override - public void setConfigParams(Map params) { - // TODO Auto-generated method stub - - } - - @Override - public Map getConfigParams() { - // TODO Auto-generated method stub - return null; - } - - @Override - public int getRunLevel() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public void setRunLevel(int level) { - // TODO Auto-generated method stub - - } - -}