ACL implements IACLService, IFloodlightModule, IDeviceListener { @Override public void deviceAdded(IDevice device) { SwitchPort[] switchPort = device.getAttachmentPoints(); if (switchPort.length == 0) { return; } IPv4Address[] ips = device.getIPv4Addresses(); if (ips.length == 0) { return; } String dpid = HexString.toHexString(switchPort[0].getSwitchDPID() .getLong()); String ip = IPv4.fromIPv4Address(ips[0].getInt()); logger.debug("AP(dpid:{},ip:{}) is added", dpid, ip); AP ap = new AP(ip, dpid); apManager.addAP(ap); processAPAdded(ap); }  @Override List<ACLRule> getRules(); @Override boolean addRule(ACLRule rule); @Override void removeRule(int ruleId); @Override void removeAllRules(); @Override Collection<Class<? extends IFloodlightService>> getModuleServices(); @Override Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls(); @Override Collection<Class<? extends IFloodlightService>> getModuleDependencies(); @Override void init(FloodlightModuleContext context); @Override void startUp(FloodlightModuleContext context); @Override void deviceAdded(IDevice device); @Override void deviceRemoved(IDevice device); @Override void deviceMoved(IDevice device); @Override void deviceIPV6AddrChanged(IDevice device); @Override void deviceIPV4AddrChanged(IDevice device); @Override void deviceVlanChanged(IDevice device); @Override String getName(); @Override boolean isCallbackOrderingPrereq(String type, String name); @Override boolean isCallbackOrderingPostreq(String type, String name);  }
@Test public void testDeviceAdded() { reset(topology); expect(topology.isAttachmentPointPort(DatapathId.of(1L), OFPort.of(1))).andReturn(true).anyTimes(); expect(topology.isAttachmentPointPort(DatapathId.of(1L), OFPort.of(2))).andReturn(true).anyTimes(); expect(topology.isAttachmentPointPort(DatapathId.of(2L), OFPort.of(1))).andReturn(true).anyTimes(); expect(topology.isAttachmentPointPort(DatapathId.of(2L), OFPort.of(2))).andReturn(true).anyTimes(); replay(topology); int[] cidr = new int[2]; ACLRule rule1, rule2; IResultSet resultSet; Iterator<IResultSet> it; Map<String, Object> row; rule1 = new ACLRule(); rule1.setNw_src("10.0.0.0/28"); cidr = IPAddressUtil.parseCIDR("10.0.0.0/28"); rule1.setNw_src_prefix(cidr[0]); rule1.setNw_src_maskbits(cidr[1]); rule1.setNw_dst("10.0.0.254/32"); cidr = IPAddressUtil.parseCIDR("10.0.0.254/32"); rule1.setNw_dst_prefix(cidr[0]); rule1.setNw_dst_maskbits(cidr[1]); rule1.setNw_proto(6); rule1.setTp_dst(80); rule1.setAction(Action.DENY); assertEquals(acl.addRule(rule1), true); assertEquals(acl.getRules().size(), 1); deviceManager.learnEntity(MacAddress.of("00:00:00:00:00:01"), VlanVid.ZERO, IPv4Address.of("10.0.0.1"), IPv6Address.NONE, DatapathId.of(1), OFPort.of(1)); resultSet = storageService.getRow( StaticFlowEntryPusher.TABLE_NAME, "ACLRule_1_00:00:00:00:00:00:00:01"); it = resultSet.iterator(); while(it.hasNext()){ row = it.next().getRow(); assertEquals(row.get("switch").toString(),"00:00:00:00:00:00:00:01"); assertEquals(row.get("priority").toString(),"30000"); assertEquals(row.get("eth_type").toString(),"2048"); assertEquals(row.get("ipv4_src").toString(),"10.0.0.0/28"); assertEquals(row.get("ipv4_dst").toString(),"10.0.0.254/32"); assertEquals(row.get("ip_proto").toString(),"6"); assertEquals(row.get("tp_dst").toString(),"80"); assertEquals(row.get("actions"), null); } deviceManager.learnEntity(MacAddress.of("00:00:00:00:00:02"), VlanVid.ZERO, IPv4Address.of("10.0.0.2"), IPv6Address.NONE, DatapathId.of(1), OFPort.of(2)); resultSet = storageService.getRow( StaticFlowEntryPusher.TABLE_NAME, "ACLRule_1_00:00:00:00:00:00:00:01"); it = resultSet.iterator(); int count = 0; while(it.hasNext()){ row = it.next().getRow(); count++; } assertEquals(count, 1); rule2 = new ACLRule(); rule2.setNw_dst("10.0.0.3/32"); cidr = IPAddressUtil.parseCIDR("10.0.0.3/32"); rule2.setNw_dst_prefix(cidr[0]); rule2.setNw_dst_maskbits(cidr[1]); rule2.setNw_proto(1); rule2.setAction(Action.DENY); assertEquals(acl.addRule(rule2), true); assertEquals(acl.getRules().size(), 2); deviceManager.learnEntity(MacAddress.of("00:00:00:00:00:03"), VlanVid.ZERO, IPv4Address.of("10.0.0.3"), IPv6Address.NONE, DatapathId.of(2), OFPort.of(1)); resultSet = storageService.getRow( StaticFlowEntryPusher.TABLE_NAME, "ACLRule_2_00:00:00:00:00:00:00:02"); it = resultSet.iterator(); while(it.hasNext()){ row = it.next().getRow(); assertEquals(row.get("switch").toString(),"00:00:00:00:00:00:00:02"); assertEquals(row.get("priority").toString(),"29999"); assertEquals(row.get("eth_type").toString(),"2048"); assertEquals(row.get("ipv4_src"), null); assertEquals(row.get("ipv4_dst").toString(),"10.0.0.3/32"); assertEquals(row.get("ip_proto").toString(),"1"); assertEquals(row.get("tp_dst"), null); assertEquals(row.get("actions"), null); } }