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 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 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); } /** ****************************************************************** */ }