private void displayBellmanFord( Host src, HashMap<String, String> predecessors, HashMap<String, Integer> fwdingToSrcPorts, HashMap<String, Integer> distances) { try { System.out.println( "\nBELLMAN FORD : src : " + src.getName() + " " + IPv4.fromIPv4Address(src.getIPv4Address())); System.out.print("Predecessors : "); for (Entry<String, String> predMapEntry : predecessors.entrySet()) { System.out.print("(" + predMapEntry.getKey() + "," + predMapEntry.getValue() + ") "); } System.out.println(); System.out.print("FwdPorts : "); for (Entry<String, Integer> mapEntry : fwdingToSrcPorts.entrySet()) { System.out.print("(" + mapEntry.getKey() + "," + mapEntry.getValue() + ") "); } System.out.println(); System.out.print("Distances : "); for (Entry<String, Integer> mapEntry : distances.entrySet()) { System.out.print("(" + mapEntry.getKey() + "," + mapEntry.getValue() + ") "); } System.out.println(); } catch (Exception e) { e.printStackTrace(); } }
/** * Event handler called when a switch leaves the network. * * @param DPID for the switch */ @Override public void switchRemoved(long switchId) { IOFSwitch sw = this.floodlightProv.getSwitch(switchId); log.info(String.format("Switch s%d removed", switchId)); /** ****************************************************************** */ /* TODO: Update routing: change routing rules for all hosts */ // check for (Host host : this.getHosts()) { OFMatch matchCriteria = new OFMatch(); matchCriteria.setDataLayerType(OFMatch.ETH_TYPE_IPV4); matchCriteria.setNetworkDestination(host.getIPv4Address()); for (IOFSwitch currSw : this.getSwitches().values()) { SwitchCommands.removeRules(currSw, this.table, matchCriteria); } updateAllRouting(); } /** ****************************************************************** */ }
/** * Event handler called when a host joins the network. * * @param device information about the host */ @Override public void deviceAdded(IDevice device) { Host host = new Host(device, this.floodlightProv); // We only care about a new host if we know its IP if (host.getIPv4Address() != null) { log.info(String.format("Host %s added", host.getName())); this.knownHosts.put(device, host); /** ************************************************************** */ /* TODO: Update routing: add rules to route to new host */ if (host.isAttachedToSwitch() != false) { // TODO : adbhat : install rules to route traffic to this host updateAllRouting(); // else nothing /** ************************************************************** */ } } }
private void installL3FwdRule(IOFSwitch currSw, Host host, int opPortTowardsSrc) { if (debug_level < 2) System.out.println( "L3 Install Rule : sw - " + String.valueOf(currSw.getId()) + " port " + opPortTowardsSrc); OFMatch matchCriteria = new OFMatch(); matchCriteria.setDataLayerType(OFMatch.ETH_TYPE_IPV4); matchCriteria.setNetworkDestination(host.getIPv4Address()); List<OFAction> actionOps = new LinkedList<OFAction>(); OFActionOutput actOp = new OFActionOutput(opPortTowardsSrc); actionOps.add(0, actOp); OFInstructionApplyActions applyActions = new OFInstructionApplyActions(actionOps); List<OFInstruction> instructionList = new ArrayList<OFInstruction>(); instructionList.add(applyActions); SwitchCommands.removeRules(currSw, this.table, matchCriteria); if (SwitchCommands.installRule( currSw, this.table, SwitchCommands.DEFAULT_PRIORITY, matchCriteria, instructionList) == false) { System.out.println( "L3 Rule not installed: sw " + String.valueOf(currSw.getId()) + " port: " + opPortTowardsSrc + " table: " + this.table); } else { if (debug_level < 2) System.out.println( "L3 Rule installed : sw " + String.valueOf(currSw.getId()) + " port: " + opPortTowardsSrc + " table: " + this.table); } }
/** * Event handler called when a host is no longer attached to a switch. * * @param device information about the host */ @Override public void deviceRemoved(IDevice device) { Host host = this.knownHosts.get(device); if (null == host) { return; } this.knownHosts.remove(host); log.info(String.format("Host %s is no longer attached to a switch", host.getName())); /** ****************************************************************** */ /* TODO: Update routing: remove rules to route to host */ OFMatch matchCriteria = new OFMatch(); matchCriteria.setDataLayerType(OFMatch.ETH_TYPE_IPV4); matchCriteria.setNetworkDestination(host.getIPv4Address()); for (IOFSwitch currSw : this.getSwitches().values()) { SwitchCommands.removeRules(currSw, this.table, matchCriteria); } /** ****************************************************************** */ }