package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation;

import java.util.Collection;
import java.util.Iterator;
import java.util.Random;

import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.NetworkManipulationAlgorithm;
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.distributionHandler.ConstantValueDistributionHandler;

public class DoSAnomaly implements NetworkManipulationAlgorithm {
	
	@Override
	public void runAlgorithm(Controller controller, long currentTimeStep) {
		
		Collection<SmartDevice> devices = controller.getNetworkController().getVisibleSmartDevices();
		if(devices.isEmpty())return;
		
		Iterator<SmartDevice> it = devices.iterator();
		
		SmartDevice hub = null;
		//Find Hub
		while(it.hasNext()){
			if(it.next().getName().equalsIgnoreCase("Hub (Broker)")) {
				hub = it.next();
				break;
			}
		}
		if(hub == null)return;
		hub.getPorts().get(0).setTriggerHandler(new ConstantValueDistributionHandler(20));
		controller.notifyObservers();
	}

}
