Java 类org.projectfloodlight.openflow.types.IPv4Address 实例源码

项目:fresco_floodlight    文件:DeviceManagerImplTest.java   
@Test
public void testGetSwitchPortVlanId() {
    Entity entity1 = new Entity(MacAddress.of(1L), VlanVid.ofVlan(1), IPv4Address.NONE, IPv6Address.NONE, DatapathId.of(10L), OFPort.of(1), new Date());
    Entity entity2 = new Entity(MacAddress.of(1L), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, DatapathId.of(10L), OFPort.of(1), new Date());
    Entity entity3 = new Entity(MacAddress.of(1L), VlanVid.ofVlan(3), IPv4Address.NONE, IPv6Address.NONE,  DatapathId.of(1L), OFPort.of(1), new Date());
    Entity entity4 = new Entity(MacAddress.of(1L), VlanVid.ofVlan(42), IPv4Address.NONE, IPv6Address.NONE,  DatapathId.of(1L), OFPort.of(1), new Date());
    Entity[] entities = new Entity[] { entity1, entity2,
            entity3, entity4
    };
    Device d = new Device(null,1L, null, null, null,
            Arrays.asList(entities), null);
    SwitchPort swp1x1 = new SwitchPort(DatapathId.of(1L), OFPort.of(1));
    SwitchPort swp1x2 = new SwitchPort(DatapathId.of(1L), OFPort.of(2));
    SwitchPort swp2x1 = new SwitchPort(DatapathId.of(2L), OFPort.of(1));
    SwitchPort swp10x1 = new SwitchPort(DatapathId.of(10L), OFPort.of(1));
    assertArrayEquals(new VlanVid[] { VlanVid.ZERO, VlanVid.ofVlan(1)},
            d.getSwitchPortVlanIds(swp10x1));
    assertArrayEquals(new VlanVid[] { VlanVid.ofVlan(3), VlanVid.ofVlan(42)},
            d.getSwitchPortVlanIds(swp1x1));
    assertArrayEquals(new VlanVid[0],
            d.getSwitchPortVlanIds(swp1x2));
    assertArrayEquals(new VlanVid[0],
            d.getSwitchPortVlanIds(swp2x1));
}
项目:iTAP-controller    文件:ACL.java   
/**
 * listen for new device
 */
@Override
public void deviceAdded(IDevice device) {
    SwitchPort[] switchPort = device.getAttachmentPoints();
    IPv4Address[] ips = device.getIPv4Addresses();
    if(ips.length == 0){
        // A new no-ip device added
        return;
    }
    String dpid = HexString.toHexString(switchPort[0].getSwitchDPID().getLong());
    String ip = IPv4.fromIPv4Address(ips[0].getInt());
    logger.info("New AP added. [dpid:" + dpid + " ip:" + ip + "]");

    AP ap = new AP(ip,dpid);
    apManager.addAP(ap);
    processAPAdded(ap);
}
项目:floodlight-simple-multicast    文件:MulticastDb.java   
public boolean joinGroup(IPv4Address groupAddr, IPv4Address hostAddr, MacAddress hostMac, DatapathId dpid, OFPort port) {
    MulticastGroup group = getGroup(groupAddr.toString());

    if (group == null) {
        log.error("Multicast group " + groupAddr + " does not exist");  
        return false;
    }   

    // if not already in group
    if (!checkHost(groupAddr.toString(), hostAddr.toString())) {
        group.addHost(hostAddr, hostMac, dpid, port);
        log.info("Adding a new host to multicast group: " +
                 hostAddr + " -> " + groupAddr +
                 " | dpid:port -> " + dpid.toString() + ":" + port.toString());         
        return true;
    }

    log.warn("Host " + hostAddr + " already part of group " + groupAddr);
    return false;
}
项目:fresco_floodlight    文件:FP_LibFloodlight.java   
@Override
public int getSrcIP(FPContext cntx) {
    FloodlightContext flCntx = cntx.getFlowContext();

    Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
    IPv4Address srcIP;

    if(eth.getEtherType() == EthType.IPv4)
    {       
        IPv4 ipv4 = (IPv4) eth.getPayload();
        srcIP = ipv4.getSourceAddress();

        return srcIP.getInt();
    }
    else if (eth.getEtherType() == EthType.ARP){
        ARP arp = (ARP) eth.getPayload();
        srcIP = arp.getSenderProtocolAddress();

        return srcIP.getInt();
    }

    //for other packets without source IP information   
    return 0;

}
项目:fresco_floodlight    文件:FP_LibFloodlight.java   
@Override
public int getDstIP(FPContext cntx) {
    FloodlightContext flCntx = cntx.getFlowContext();

    Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
    IPv4Address dstIP;

    if(eth.getEtherType() == EthType.IPv4)
    {       
        IPv4 ipv4 = (IPv4) eth.getPayload();
        dstIP = ipv4.getDestinationAddress();
        return dstIP.getInt();
    }
    else if (eth.getEtherType() == EthType.ARP){
        ARP arp = (ARP) eth.getPayload();

        dstIP = arp.getTargetProtocolAddress();

        return dstIP.getInt();
    }

    //for other packets without destination IP information
    return 0;

}
项目:iTAP-controller    文件:ObfuscationController.java   
private void sendArpReply(MacAddress senderMac, IPv4Address senderIp, MacAddress targetMac, IPv4Address targetIp, IOFSwitch sw, OFPort port) {
    IPacket arpReply = new Ethernet()
        .setSourceMACAddress(senderMac)
        .setDestinationMACAddress(targetMac)
        .setEtherType(EthType.ARP)
        .setPayload(
            new ARP()
            .setHardwareType(ARP.HW_TYPE_ETHERNET)
            .setProtocolType(ARP.PROTO_TYPE_IP)
            .setHardwareAddressLength((byte) 6)
            .setProtocolAddressLength((byte) 4)
            .setOpCode(ARP.OP_REPLY)
            .setSenderHardwareAddress(senderMac.getBytes())
            .setSenderProtocolAddress(senderIp.getBytes())
            .setTargetHardwareAddress(targetMac.getBytes())
            .setTargetProtocolAddress(targetIp.getBytes()));
       pushPacket(arpReply, sw, OFBufferId.NO_BUFFER, OFPort.ANY, port);
}
项目:fresco_floodlight    文件:DeviceManagerImplTest.java   
/**
 * Verify that the given device exactly matches the given fields. E.g.,
 * if ip is not null we expect the device to have exactly one IP address.
 * swId and port are the attachment point port.
 * Vlan and ip are optional all other fields must be specified.
 * @return
 */
private static void verifyDevice(IDevice d, MacAddress mac, VlanVid vlan, IPv4Address ipv4,
        IPv6Address ipv6, DatapathId swId, OFPort port) {
    assertNotNull(d);
    if (!mac.equals(MacAddress.NONE)) {
        assertEquals(mac, d.getMACAddress());
    }
    if (vlan != null) {
        assertArrayEquals(new VlanVid[] { vlan }, d.getVlanId());
    }
    if (!ipv4.equals(IPv4Address.NONE)) {
        assertArrayEquals(new IPv4Address[] { ipv4 }, d.getIPv4Addresses());
    }
    if (!ipv6.equals(IPv6Address.NONE)) {
        assertArrayEquals(new IPv6Address[] { ipv6 }, d.getIPv6Addresses());
    }
    if (!swId.equals(DatapathId.NONE) && !port.equals(OFPort.ZERO)) {
        SwitchPort expectedAp = new SwitchPort(swId, port);
        assertArrayEquals(new SwitchPort[] { expectedAp }, d.getAttachmentPoints());
    }
}
项目:iTAP-controller    文件:DeviceUniqueIndexTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    e1a = new Entity(MacAddress.of(1L), VlanVid.ofVlan(1), IPv4Address.of(1), DatapathId.of(1L), OFPort.of(1), new Date());
    e1b = new Entity(MacAddress.of(1L), VlanVid.ofVlan(2), IPv4Address.of(1), DatapathId.of(1L), OFPort.of(1), new Date());
    List<Entity> d1Entities = new ArrayList<Entity>(2);
    d1Entities.add(e1a);
    d1Entities.add(e1b);
    d1 = new Device(null, Long.valueOf(1), null, null, null,
                    d1Entities, null);

    // e2 and e2 alt match in MAC and VLAN
    e2 = new Entity(MacAddress.of(2L), VlanVid.ofVlan(2), IPv4Address.of(2), DatapathId.of(2L), OFPort.of(2), new Date());
    e2alt = new Entity(MacAddress.of(2L), VlanVid.ofVlan(2), null, null, null, null);

    // IP is null
    e3 = new Entity(MacAddress.of(3L), VlanVid.ofVlan(3), null, DatapathId.of(3L), OFPort.of(3), new Date());

    // IP and switch and port are null
    e4 = new Entity(MacAddress.of(4L), VlanVid.ofVlan(4), null, null, null, new Date());
}
项目:fresco_floodlight    文件:VirtualNetworkFilter.java   
@Override
public void init(FloodlightModuleContext context)
        throws FloodlightModuleException {
    floodlightProviderService = context.getServiceImpl(IFloodlightProviderService.class);
    restApiService = context.getServiceImpl(IRestApiService.class);
    deviceService = context.getServiceImpl(IDeviceService.class);

    vNetsByGuid = new ConcurrentHashMap<String, VirtualNetwork>();
    nameToGuid = new ConcurrentHashMap<String, String>();
    guidToGateway = new ConcurrentHashMap<String, IPv4Address>();
    gatewayToGuid = new ConcurrentHashMap<IPv4Address, Set<String>>();
    macToGuid = new ConcurrentHashMap<MacAddress, String>();
    portToMac = new ConcurrentHashMap<String, MacAddress>();
    macToGateway = new ConcurrentHashMap<MacAddress, IPv4Address>();
    deviceListener = new DeviceListenerImpl();

}
项目:iTAP-controller    文件:DeviceManagerImpl.java   
private EnumSet<DeviceField> getEntityKeys(MacAddress macAddress,
     VlanVid vlan,
     IPv4Address ipv4Address,
     DatapathId switchDPID,
     OFPort switchPort) {
 // FIXME: vlan==null is a valid search. Need to handle this
 // case correctly. Note that the code will still work correctly.
 // But we might do a full device search instead of using an index.
 EnumSet<DeviceField> keys = EnumSet.noneOf(DeviceField.class);
 if (macAddress != null) keys.add(DeviceField.MAC);
 if (vlan != null) keys.add(DeviceField.VLAN);
 if (ipv4Address != null) keys.add(DeviceField.IPV4);
 if (switchDPID != null) keys.add(DeviceField.SWITCH);
 if (switchPort != null) keys.add(DeviceField.PORT);
 return keys;
}
项目:fresco_floodlight    文件:ACL.java   
@Override
public void deviceIPV4AddrChanged(IDevice device) {

    SwitchPort[] switchPort = device.getAttachmentPoints();
    IPv4Address[] ips = device.getIPv4Addresses();

    String dpid = HexString.toHexString(switchPort[0].getSwitchDPID()
            .getLong());
    String ip = null;
    // some device may first appear with no IP address(default set to
    // 0.0.0.0), ignore it
    for (IPv4Address i : ips) {
        if (i.getInt() != 0) {
            ip = IPv4.fromIPv4Address(i.getInt());
            break;
        }
    }

    logger.debug("AP(dpid:{},ip:{}) is added", dpid, ip);
    AP ap = new AP(ip, dpid);
    apManager.addAP(ap);
    processAPAdded(ap);
}
项目:iTAP-controller    文件:VirtualNetworkFilter.java   
@Override
public void init(FloodlightModuleContext context)
        throws FloodlightModuleException {
    floodlightProviderService = context.getServiceImpl(IFloodlightProviderService.class);
    restApiService = context.getServiceImpl(IRestApiService.class);
    deviceService = context.getServiceImpl(IDeviceService.class);

    vNetsByGuid = new ConcurrentHashMap<String, VirtualNetwork>();
    nameToGuid = new ConcurrentHashMap<String, String>();
    guidToGateway = new ConcurrentHashMap<String, IPv4Address>();
    gatewayToGuid = new ConcurrentHashMap<IPv4Address, Set<String>>();
    macToGuid = new ConcurrentHashMap<MacAddress, String>();
    portToMac = new ConcurrentHashMap<String, MacAddress>();
    macToGateway = new ConcurrentHashMap<MacAddress, IPv4Address>();
    deviceListener = new DeviceListenerImpl();

}
项目:fresco_floodlight    文件:DHCPPool.java   
/**
 * Completely removes the DHCPBinding object with IP address {@code byte[]} ip from the DHCPPool
 * @param {@code byte[]} ip: The IP address to remove from the pool. This address will not be available
 * for lease after removal.
 * @return none
 */
public void removeIPv4FromDHCPPool(IPv4Address ip) {
    if (ip == null || getDHCPbindingFromIPv4(ip) == null) return;
    if (ip.equals(STARTING_ADDRESS)) {
        DHCPBinding lowest = null;
        // Locate the lowest address (other than ip), which will be the new starting address
        for (DHCPBinding binding : DHCP_POOL) {
            if (lowest == null) {
                lowest = binding;
            } else if (binding.getIPv4Address().getInt() < lowest.getIPv4Address().getInt()
                    && !binding.getIPv4Address().equals(ip))
            {
                lowest = binding;
            }
        }
        // lowest is new starting address
        STARTING_ADDRESS = lowest.getIPv4Address();
    }
    DHCP_POOL.remove(this.getDHCPbindingFromIPv4(ip));
    this.setPoolSize(this.getPoolSize() - 1);
    this.setPoolAvailability(this.getPoolAvailability() - 1);
    if (this.getPoolAvailability() == 0) this.setPoolFull(true);
}
项目:iTAP-controller    文件:DeviceManagerImplTest.java   
@Test
public void testLastSeen() throws Exception {
    Calendar c = Calendar.getInstance();
    Date d1 = c.getTime();
    Entity entity1 = new Entity(MacAddress.of(1L), null, null, null, null, d1);
    c.add(Calendar.SECOND, 1);
    Entity entity2 = new Entity(MacAddress.of(1L), null, IPv4Address.of(1), null, null, c.getTime());

    IDevice d = deviceManager.learnDeviceByEntity(entity2);
    assertEquals(c.getTime(), d.getLastSeen());
    d = deviceManager.learnDeviceByEntity(entity1);
    assertEquals(c.getTime(), d.getLastSeen());

    deviceManager.startUp(null);
    d = deviceManager.learnDeviceByEntity(entity1);
    assertEquals(d1, d.getLastSeen());
    d = deviceManager.learnDeviceByEntity(entity2);
    assertEquals(c.getTime(), d.getLastSeen());
}
项目:iTAP-controller    文件:ObfuscationController.java   
private void handleARP(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
    Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);

    if (! (eth.getPayload() instanceof ARP)) // not an ARP packet
        return;

    ARP arpRequest = (ARP) eth.getPayload();

    if (arpRequest.getOpCode() == ARP.OP_REPLY) { // is a reply
        oTopologyManager.updateTopologyMappings(sw, pi, cntx);

        for (ARP pendingArpRequest : arpRequestBuffer.getPendingRequests(IPv4Address.of(arpRequest.getSenderProtocolAddress()))) {              
            if (oTopologyManager.knowSwitchForIp(IPv4Address.of(pendingArpRequest.getSenderProtocolAddress()))) {
                SwitchHostInfo dstSwitchPort = oTopologyManager.getSwitchForIp(IPv4Address.of(pendingArpRequest.getSenderProtocolAddress()));
                sendArpReply(MacAddress.of(arpRequest.getSenderHardwareAddress()), IPv4Address.of(arpRequest.getSenderProtocolAddress()), MacAddress.of(pendingArpRequest.getSenderHardwareAddress()), IPv4Address.of(pendingArpRequest.getSenderProtocolAddress()), dstSwitchPort.getSwitch(), dstSwitchPort.getPort());
                arpRequestBuffer.removeRequest(pendingArpRequest);
            }
            else
                log.warn("answering pending ARP request failed because dst switch/port is not known. {}",pendingArpRequest);
        }
    }
    else { // is a request
        if (IPv4Address.of(arpRequest.getSenderProtocolAddress()).toString().contentEquals("10.0.0.111")) // ignore crafted requests from switches
            return;

        if (oTopologyManager.knowMacForIp(IPv4Address.of(arpRequest.getTargetProtocolAddress()))) {
            MacAddress senderMac = oTopologyManager.getMacForIp(IPv4Address.of(arpRequest.getTargetProtocolAddress()));
            sendArpReply(senderMac, IPv4Address.of(arpRequest.getTargetProtocolAddress()), MacAddress.of(arpRequest.getSenderHardwareAddress()), IPv4Address.of(arpRequest.getSenderProtocolAddress()), sw, pi.getMatch().get(MatchField.IN_PORT));
        }
        else {
            arpRequestBuffer.addRequest(arpRequest);
            for (DatapathId swi : switchService.getAllSwitchDpids())
                floodArpRequest(switchService.getSwitch(swi),IPv4Address.of(arpRequest.getTargetProtocolAddress()));
        }
    }
}
项目:iTAP-controller    文件:Device.java   
@Override
public IPv4Address[] getIPv4Addresses() {
    // XXX - TODO we can cache this result.  Let's find out if this
    // is really a performance bottleneck first though.

    TreeSet<IPv4Address> vals = new TreeSet<IPv4Address>();
    for (Entity e : entities) {
        if (e.getIpv4Address() == null) continue;

        // We have an IP address only if among the devices within the class
        // we have the most recent entity with that IP.
        boolean validIP = true;
        Iterator<Device> devices =
                deviceManager.queryClassByEntity(entityClass, ipv4Fields, e);
        while (devices.hasNext()) {
            Device d = devices.next();
            if (deviceKey.equals(d.getDeviceKey()))
                continue;
            for (Entity se : d.entities) {
                if (se.getIpv4Address() != null &&
                        se.getIpv4Address().equals(e.getIpv4Address()) &&
                        se.getLastSeenTimestamp() != null &&
                        0 < se.getLastSeenTimestamp().
                        compareTo(e.getLastSeenTimestamp())) {
                    validIP = false;
                    break;
                }
            }
            if (!validIP)
                break;
        }

        if (validIP)
            vals.add(e.getIpv4Address());
    }

    return vals.toArray(new IPv4Address[vals.size()]);
}
项目:floodlight-simple-multicast    文件:MulticastDb.java   
public boolean leaveGroup(IPv4Address groupAddr, IPv4Address hostAddr) {
    MulticastGroup group = getGroup(groupAddr.toString());

    if (group == null) {
        log.error("Multicast group " + groupAddr + " does not exist");  
        return false;
    }

    group.deleteHost(hostAddr);

    return true;
}
项目:iTAP-controller    文件:MockDevice.java   
@Override
public IPv4Address[] getIPv4Addresses() {
    TreeSet<IPv4Address> vals = new TreeSet<IPv4Address>();
    for (Entity e : entities) {
        if (e.getIpv4Address() == null) continue;
        vals.add(e.getIpv4Address());
    }

    return vals.toArray(new IPv4Address[vals.size()]);
}
项目:floodlight-simple-multicast    文件:MulticastGroup.java   
public MCHost getHost(IPv4Address addr) {
    MCHost h_ret = null;
    for(MCHost h : hosts) {
        if (addr.compareTo(h.addr) == 0) {
            h_ret = h;
            break;
        }
    }
    return h_ret;
}
项目:floodlight-simple-multicast    文件:MulticastGroup.java   
public MulticastGroup deleteHost(IPv4Address addr) {
    MCHost h_del = null;
    for(MCHost h : hosts) {
        if (h.addr.toString().equals(addr.toString())) {
            h_del = h;
            break;
        }
    }
    if (h_del != null)
        hosts.remove(h_del);    

    return this;
}
项目:iTAP-controller    文件:ObfuscationMask.java   
public int querySourceId(MacAddress mac, IPv4Address ip, IpProtocol protocol, TransportPort port) {
    if (!oPolicy.doRewrite(ObfuscationPolicy.Field.MAC_SRC))
        mac = MacAddress.of(1);
    if (!oPolicy.doRewrite(ObfuscationPolicy.Field.IP_SRC))
        ip = IPv4Address.of(1);
    if (!(oPolicy.doRewrite(ObfuscationPolicy.Field.TP_SRC) && oPolicy.doRewrite(port.getPort())))
        port = TransportPort.of(0);

    return queryHostId(0, mac, ip, protocol, port);
}
项目:iTAP-controller    文件:DHCPPool.java   
/**
 * Gets the DHCPBinding object from the DHCPPool containing {@code byte[]} ip
 * @param {@code byte[]} ip: The IPv4 address to match in a DHCPBinding
 * @return {@code DHCPBinding}: The matching DHCPBinding object or null if ip is not found
 */
public DHCPBinding getDHCPbindingFromIPv4(IPv4Address ip) {
    if (ip == null) return null;
    for (DHCPBinding binding : DHCP_POOL) {
        if (binding.getIPv4Address().equals(ip)) {
            return binding;
        }
    }
    return null;
}
项目:iTAP-controller    文件:DHCPPool.java   
/**
 * Constructor for a DHCPPool of DHCPBinding's. Each DHCPBinding object is initialized with a
 * null MAC address and the lease is set to inactive (i.e. false).
 * @param {@code byte[]} startingIPv4Address: The lowest IP address to lease.
 * @param {@code integer} size: (startingIPv4Address + size) is the highest IP address to lease.
 * @return none
 */
public DHCPPool(IPv4Address startingIPv4Address, int size, Logger log) {
    this.log = log;
    int IPv4AsInt = startingIPv4Address.getInt();
    this.setPoolSize(size);
    this.setPoolAvailability(size);
    STARTING_ADDRESS = startingIPv4Address;
    for (int i = 0; i < size; i++) { 
        DHCP_POOL.add(new DHCPBinding(IPv4Address.of(IPv4AsInt + i), UNASSIGNED_MAC));
    }

}
项目:fresco_floodlight    文件:Device.java   
@Override
public IPv4Address[] getIPv4Addresses() {
    // XXX - TODO we can cache this result. Let's find out if this
    // is really a performance bottleneck first though.

    TreeSet<IPv4Address> vals = new TreeSet<IPv4Address>();
    for (Entity e : entities) {
        if (e.getIpv4Address().equals(IPv4Address.NONE))
            continue;

        // We have an IP address only if among the devices within the class
        // we have the most recent entity with that IP.
        boolean validIP = true;
        Iterator<Device> devices = deviceManager.queryClassByEntity(
                entityClass, ipv4Fields, e);
        while (devices.hasNext()) {
            Device d = devices.next();
            if (deviceKey.equals(d.getDeviceKey()))
                continue;
            for (Entity se : d.entities) {
                if (se.getIpv4Address() != null
                        && se.getIpv4Address().equals(e.getIpv4Address())
                        && !se.getLastSeenTimestamp()
                                .equals(Entity.NO_DATE)
                        && 0 < se.getLastSeenTimestamp().compareTo(
                                e.getLastSeenTimestamp())) {
                    validIP = false;
                    break;
                }
            }
            if (!validIP)
                break;
        }

        if (validIP)
            vals.add(e.getIpv4Address());
    }

    return vals.toArray(new IPv4Address[vals.size()]);
}
项目:fresco_floodlight    文件:DeviceManagerImpl.java   
/**
 * Get sender IPv4 address from packet if the packet is an ARP
 * packet and if the source MAC address matches the ARP packets
 * sender MAC address.
 * @param eth
 * @param dlAddr
 * @return
 */
private IPv4Address getSrcIPv4AddrFromARP(Ethernet eth, MacAddress dlAddr) {
    if (eth.getPayload() instanceof ARP) {
        ARP arp = (ARP) eth.getPayload();
        if ((arp.getProtocolType() == ARP.PROTO_TYPE_IP) && (arp.getSenderHardwareAddress().equals(dlAddr))) {
            return arp.getSenderProtocolAddress();
        }
    }
    return IPv4Address.NONE;
}
项目:fresco_floodlight    文件:DeviceManagerImpl.java   
/**
 * Learn device from ARP data in scenarios where the
 * Ethernet source MAC is different from the sender hardware
 * address in ARP data.
 */
protected void learnDeviceFromArpResponseData(Ethernet eth,
        DatapathId swdpid,
        OFPort port) {

    if (!(eth.getPayload() instanceof ARP)) return;
    ARP arp = (ARP) eth.getPayload();

    MacAddress dlAddr = eth.getSourceMACAddress();

    MacAddress senderAddr = arp.getSenderHardwareAddress();

    if (dlAddr.equals(senderAddr)) return; // arp request

    // Ignore broadcast/multicast source
    if (senderAddr.isBroadcast() || senderAddr.isMulticast())
        return;
    // Ignore zero sender mac
    if (senderAddr.equals(MacAddress.of(0)))
        return;

    VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
    IPv4Address nwSrc = arp.getSenderProtocolAddress();

    Entity e =  new Entity(senderAddr,
            vlan, /* will either be a valid tag or VlanVid.ZERO if untagged */
            nwSrc,
            IPv6Address.NONE, /* must be none for ARP */
            swdpid,
            port,
            new Date());

    learnDeviceByEntity(e);
}
项目:fresco_floodlight    文件:DeviceManagerImpl.java   
/**
 * Get a (partial) entity for the destination from the packet.
 * @param eth
 * @return
 */
protected Entity getDestEntityFromPacket(Ethernet eth) {
    MacAddress dlAddr = eth.getDestinationMACAddress();
    VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
    IPv4Address ipv4Dst = IPv4Address.NONE;
    IPv6Address ipv6Dst = IPv6Address.NONE;

    // Ignore broadcast/multicast destination
    if (dlAddr.isBroadcast() || dlAddr.isMulticast())
        return null;
    // Ignore zero dest mac
    if (dlAddr.equals(MacAddress.of(0)))
        return null;

    if (eth.getPayload() instanceof IPv4) {
        IPv4 ipv4 = (IPv4) eth.getPayload();
        ipv4Dst = ipv4.getDestinationAddress();
    } else if (eth.getPayload() instanceof IPv6) {
        IPv6 ipv6 = (IPv6) eth.getPayload();
        ipv6Dst = ipv6.getDestinationAddress();
    }

    return new Entity(dlAddr,
            vlan,
            ipv4Dst,
            ipv6Dst,
            DatapathId.NONE,
            OFPort.ZERO,
            Entity.NO_DATE);
}
项目:fresco_floodlight    文件:DeviceManagerImpl.java   
/**
 * Check if the entity e has all the keyFields set. Returns false if not
 * @param e entity to check
 * @param keyFields the key fields to check e against
 * @return
 */
protected boolean allKeyFieldsPresent(Entity e, EnumSet<DeviceField> keyFields) {
 for (DeviceField f : keyFields) {
     switch (f) {
     case MAC:
         // MAC address is always present
         break;
     case IPv4:
     case IPv6:
         if (e.ipv4Address.equals(IPv4Address.NONE) && e.ipv6Address.equals(IPv6Address.NONE)) {
             return false; // mutually exclusive
         }
         break;
     case SWITCH:
         if (e.switchDPID.equals(DatapathId.NONE)) {
             return false;
         }
         break;
     case PORT:
         if (e.switchPort.equals(OFPort.ZERO)) {
             return false;
         }
         break;
     case VLAN:
         if (e.vlan == null) { /* VLAN is null for 'don't care' or 'unspecified'. It's VlanVid.ZERO for untagged. */
             return false;     /* For key field of VLAN, the VLAN **MUST** be set to either ZERO or some value. */
         }
         break;
     default:
         // we should never get here. unless somebody extended
         // DeviceFields
         throw new IllegalStateException();
     }
 }
 return true;
}
项目:fresco_floodlight    文件:DeviceManagerImpl.java   
public DeviceEvent(MacAddress macAddress, List<IPv4Address> ipv4Addresses,
     List<IPv6Address> ipv6Addresses,
     List<SwitchPort> oldAttachmentPoints,
     List<SwitchPort> currentAttachmentPoints,
     List<VlanVid> vlanIds, String reason) {
 super();
 this.macAddress = macAddress;
 this.ipv4Addresses = ipv4Addresses;
 this.ipv6Addresses = ipv6Addresses;
 this.oldAttachmentPoints = oldAttachmentPoints;
 this.currentAttachmentPoints = currentAttachmentPoints;
 this.vlanIds = vlanIds;
 this.reason = reason;
}
项目:iTAP-controller    文件:ObfuscationController.java   
private void floodArpRequest(IOFSwitch sw, IPv4Address requestedAddress) {
    IPacket arpRequest = new Ethernet()
    .setSourceMACAddress("00:00:00:00:00:01")
    .setDestinationMACAddress("ff:ff:ff:ff:ff:ff")
    .setEtherType(EthType.ARP)
    .setVlanID((short) 0)
    .setPriorityCode((byte) 0)
    .setPayload(
            new ARP()
            .setHardwareType(ARP.HW_TYPE_ETHERNET)
            .setProtocolType(ARP.PROTO_TYPE_IP)
            .setHardwareAddressLength((byte) 6)
            .setProtocolAddressLength((byte) 4)
            .setOpCode(ARP.OP_REQUEST)
            .setSenderHardwareAddress(HexString.fromHexString("00:00:00:00:00:01"))
            .setSenderProtocolAddress(IPv4.toIPv4AddressBytes("10.0.0.111"))
            .setTargetHardwareAddress(HexString.fromHexString("00:00:00:00:00:00"))
            .setTargetProtocolAddress(requestedAddress.getBytes()));

       Set<OFPort> portsConnectedToSwitches = new HashSet<OFPort>();

       for (Link link : linkDiscoveryService.getSwitchLinks().get(sw.getId())) {
        if (link.getSrc() == sw.getId())
            portsConnectedToSwitches.add(link.getSrcPort());
       }

       for (OFPortDesc port : sw.getPorts()) {
        if (!portsConnectedToSwitches.contains(port.getPortNo())) {
            pushPacket(arpRequest, sw, OFBufferId.NO_BUFFER, OFPort.ANY, port.getPortNo());
        }
       }
}
项目:iTAP-controller    文件:ObfuscationMask.java   
public int queryDestinationId(MacAddress mac, IPv4Address ip, IpProtocol protocol, TransportPort port) {
    if (!oPolicy.doRewrite(ObfuscationPolicy.Field.MAC_DST))
        mac = MacAddress.of(1);
    if (!oPolicy.doRewrite(ObfuscationPolicy.Field.IP_DST))
        ip = IPv4Address.of(1);
    if (!(oPolicy.doRewrite(ObfuscationPolicy.Field.TP_DST) && oPolicy.doRewrite(port.getPort())))
        port = TransportPort.of(0);

    return queryHostId(1, mac, ip, protocol, port);
}
项目:iTAP-controller    文件:DeviceManagerImpl.java   
protected Iterator<Device> getDeviceIteratorForQuery(MacAddress macAddress,
        VlanVid vlan,
        IPv4Address ipv4Address,
        DatapathId switchDPID,
        OFPort switchPort) {
    DeviceIndex index = null;
    if (secondaryIndexMap.size() > 0) {
        EnumSet<DeviceField> keys =
                getEntityKeys(macAddress, vlan, ipv4Address,
                        switchDPID, switchPort);
        index = secondaryIndexMap.get(keys);
    }

    Iterator<Device> deviceIterator = null;
    if (index == null) {
        // Do a full table scan
        deviceIterator = deviceMap.values().iterator();
    } else {
        // index lookup
        Entity entity = new Entity(macAddress,
                vlan,
                ipv4Address,
                switchDPID,
                switchPort,
                null);
        deviceIterator =
                new DeviceIndexInterator(this, index.queryByEntity(entity));
    }

    DeviceIterator di =
            new DeviceIterator(deviceIterator,
                    null,
                    macAddress,
                    vlan,
                    ipv4Address,
                    switchDPID,
                    switchPort);
    return di;
}
项目:fresco_floodlight    文件:DeviceSyncRepresentation.java   
public Entity asEntity() {
    Entity e = new Entity(MacAddress.of(macAddress), 
            VlanVid.ofVlan(vlan), 
            IPv4Address.of(ipv4Address), 
            IPv6Address.NONE,
            DatapathId.of(switchDPID),
            OFPort.of(switchPort), 
            lastSeenTimestamp);
    e.setActiveSince(activeSince);
    return e;
}
项目:fresco_floodlight    文件:DeviceManagerImplTest.java   
private void assertDeviceIps(IPv4Address[] expected, IDevice d) {
    List<IPv4Address> expectedList = Arrays.asList(expected);
    Collections.sort(expectedList);
    List<IPv4Address> actualList = Arrays.asList(d.getIPv4Addresses());
    Collections.sort(actualList);
    assertEquals(expectedList, actualList);
}
项目:fresco_floodlight    文件:CustomFormatters.java   
@Override
public EventResourceBuilder
        customFormat(@Nullable Collection<IPv4Address> ipv4Addresses2,
                     String name, EventResourceBuilder edb) {
    if (ipv4Addresses2 != null) {
        String ipv4AddressesStr2 = "--";
        if (!ipv4Addresses2.isEmpty()) {
            ipv4AddressesStr2 = Joiner.on(" ").join(ipv4Addresses2);
        }
        edb.dataFields.add(new Metadata(name, ipv4AddressesStr2));
    }
    return edb;
}
项目:fresco_floodlight    文件:VirtualNetworkFilter.java   
/**
 * Deletes a gateway for a virtual network.
 * @param guid The ID (not name) of the network to delete
 * the gateway for.
 */
protected void deleteGateway(String guid) {
    IPv4Address gwIp = guidToGateway.remove(guid);
    if (gwIp == null) return;
    Set<String> gSet = gatewayToGuid.get(gwIp);
    gSet.remove(guid);
    if (vNetsByGuid.get(guid) != null)
        vNetsByGuid.get(guid).setGateway(null);
}
项目:fresco_floodlight    文件:VirtualNetworkFilter.java   
@Override
public void createNetwork(String guid, String network, IPv4Address gateway) {
    if (log.isDebugEnabled()) {
        String gw = null;
        try {
            gw = gateway.toString();
        } catch (Exception e) {
            // fail silently
        }
        log.debug("Creating network {} with ID {} and gateway {}",
                new Object[] {network, guid, gw});
    }

    if (!nameToGuid.isEmpty()) {
        // We have to iterate all the networks to handle name/gateway changes
        for (Entry<String, String> entry : nameToGuid.entrySet()) {
            if (entry.getValue().equals(guid)) {
                nameToGuid.remove(entry.getKey());
                break;
            }
        }
    }
    if(network != null)
        nameToGuid.put(network, guid);
    if (vNetsByGuid.containsKey(guid))
        vNetsByGuid.get(guid).setName(network); //network already exists, just updating name
    else
        vNetsByGuid.put(guid, new VirtualNetwork(network, guid)); //new network

    // If they don't specify a new gateway the old one will be preserved
    if ((gateway != null) && (gateway.getInt() != 0)) {
        addGateway(guid, gateway);
        if (vNetsByGuid.get(guid) != null)
            vNetsByGuid.get(guid).setGateway(gateway.toString());
    }
}
项目:iTAP-controller    文件:DeviceManagerImplTest.java   
@Test
public void testSyncEntity() {
    Date d1 = new Date();
    Date d2 = new Date(0);
    Entity e1 = new Entity(MacAddress.of(1L), VlanVid.ofVlan(2), IPv4Address.of(3), DatapathId.of(4L), OFPort.of(5), d1);
    e1.setActiveSince(d2);
    SyncEntity se1 = new SyncEntity(e1);
    assertEntityEquals(e1, se1);
    assertEquals(1L, se1.macAddress);
    assertEquals(2, se1.vlan);
    assertEquals(3, se1.ipv4Address);
    assertEquals(4L, se1.switchDPID);
    assertEquals(5, se1.switchPort);
    assertEquals(d1, se1.lastSeenTimestamp);
    assertEquals(d2, se1.activeSince);
    assertNotSame(d1, se1.lastSeenTimestamp);
    assertNotSame(d2, se1.activeSince);

    Entity e2 = new Entity(MacAddress.of(42L), null, null, null, null, null);
    SyncEntity se2 = new SyncEntity(e2);
    assertEntityEquals(e2, se2);

    SyncEntity se3 = new SyncEntity();
    SyncEntity se4 = new SyncEntity();
    se3.lastSeenTimestamp = new Date(1000);
    se4.lastSeenTimestamp = new Date(2000);
    assertTrue("", se3.compareTo(se4) < 0);
    assertTrue("", se4.compareTo(se3) > 0);
    se4.lastSeenTimestamp = new Date(1000);
    assertTrue("", se3.compareTo(se4) == 0);
    assertTrue("", se4.compareTo(se3) == 0);
    se4.lastSeenTimestamp = new Date(500);
    assertTrue("", se3.compareTo(se4) > 0);
    assertTrue("", se4.compareTo(se3) < 0);
}
项目:iTAP-controller    文件:CustomFormatters.java   
@Override
public EventResourceBuilder
        customFormat(@Nullable Collection<IPv4Address> ipv4Addresses2,
                     String name, EventResourceBuilder edb) {
    if (ipv4Addresses2 != null) {
        String ipv4AddressesStr2 = "--";
        if (!ipv4Addresses2.isEmpty()) {
            ipv4AddressesStr2 = Joiner.on(" ").join(ipv4Addresses2);
        }
        edb.dataFields.add(new Metadata(name, ipv4AddressesStr2));
    }
    return edb;
}
项目:fresco_floodlight    文件:DeviceManagerImplTest.java   
private void doTestEntityOrdering(boolean computeInsertionPoint) throws Exception {
    Entity e = new Entity(MacAddress.of(10L), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, DatapathId.NONE, OFPort.ZERO, Entity.NO_DATE);
    IEntityClass ec = createNiceMock(IEntityClass.class);
    Device d = new Device(deviceManager, 1L, e, ec);

    int expectedLength = 1;
    Long[] macs = new Long[] {  5L,  // new first element
            15L,  // new last element
            7L,  // insert in middle
            12L,  // insert in middle
            6L,  // insert at idx 1
            14L,  // insert at idx length-2
            1L,
            20L
    };

    for (Long mac: macs) {
        e = new Entity(MacAddress.of(mac), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, DatapathId.NONE, OFPort.ZERO, Entity.NO_DATE);
        int insertionPoint;
        if (computeInsertionPoint) {
            insertionPoint = -(Arrays.binarySearch(d.entities, e)+1);
        } else {
            insertionPoint = -1;
        }
        d = deviceManager.allocateDevice(d, e, insertionPoint);
        expectedLength++;
        assertEquals(expectedLength, d.entities.length);
        for (int i = 0; i < d.entities.length-1; i++)
            assertEquals(-1, d.entities[i].compareTo(d.entities[i+1]));
    }
}