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

项目:fresco_floodlight    文件:LinkDiscoveryManagerTest.java   
@Test
public void testDeleteLinkToSelf() throws Exception {
    LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager();

    Link lt = new Link(DatapathId.of(1L), OFPort.of(2), DatapathId.of(1L), OFPort.of(3), U64.ZERO);
    NodePortTuple srcNpt = new NodePortTuple(DatapathId.of(1L), OFPort.of(2));
    NodePortTuple dstNpt = new NodePortTuple(DatapathId.of(2L), OFPort.of(3));

    LinkInfo info = new LinkInfo(new Date(),
            new Date(), null);
    linkDiscovery.addOrUpdateLink(lt, info);
    linkDiscovery.deleteLinks(Collections.singletonList(lt), "Test to self");

    // check invariants hold
    assertNull(linkDiscovery.switchLinks.get(lt.getSrc()));
    assertNull(linkDiscovery.switchLinks.get(lt.getDst()));
    assertNull(linkDiscovery.portLinks.get(srcNpt));
    assertNull(linkDiscovery.portLinks.get(dstNpt));
    assertTrue(linkDiscovery.links.isEmpty());
}
项目:iTAP-controller    文件:TopologyManager.java   
public void removeSwitch(DatapathId sid) {
    // Delete all the links in the switch, switch and all
    // associated data should be deleted.
    if (switchPorts.containsKey(sid) == false) return;

    // Check if any tunnel ports need to be removed.
    for(NodePortTuple npt: tunnelPorts) {
        if (npt.getNodeId() == sid) {
            removeTunnelPort(npt.getNodeId(), npt.getPortId());
        }
    }

    Set<Link> linksToRemove = new HashSet<Link>();
    for(OFPort p: switchPorts.get(sid)) {
        NodePortTuple n1 = new NodePortTuple(sid, p);
        linksToRemove.addAll(switchPortLinks.get(n1));
    }

    if (linksToRemove.isEmpty()) return;

    for(Link link: linksToRemove) {
        removeLink(link);
    }
}
项目:iTAP-controller    文件:OFSwitchManager.java   
public SwitchUpdate(DatapathId swId,
        SwitchUpdateType switchUpdateType,
        OFPortDesc port,
        PortChangeType changeType) {
    if (switchUpdateType == SwitchUpdateType.PORTCHANGED) {
        if (port == null) {
            throw new NullPointerException("Port must not be null " +
                    "for PORTCHANGED updates");
        }
        if (changeType == null) {
            throw new NullPointerException("ChangeType must not be " +
                    "null for PORTCHANGED updates");
        }
    } else {
        if (port != null || changeType != null) {
            throw new IllegalArgumentException("port and changeType " +
                    "must be null for " + switchUpdateType +
                    " updates");
        }
    }
    this.swId = swId;
    this.switchUpdateType = switchUpdateType;
    this.port = port;
    this.changeType = changeType;
}
项目:iTAP-controller    文件:TopologyManager.java   
@Override
public void init(FloodlightModuleContext context)
        throws FloodlightModuleException {
    linkDiscoveryService = context.getServiceImpl(ILinkDiscoveryService.class);
    threadPoolService = context.getServiceImpl(IThreadPoolService.class);
    floodlightProviderService = context.getServiceImpl(IFloodlightProviderService.class);
    switchService = context.getServiceImpl(IOFSwitchService.class);
    restApiService = context.getServiceImpl(IRestApiService.class);
    debugCounterService = context.getServiceImpl(IDebugCounterService.class);
    debugEventService = context.getServiceImpl(IDebugEventService.class);

    switchPorts = new HashMap<DatapathId, Set<OFPort>>();
    switchPortLinks = new HashMap<NodePortTuple, Set<Link>>();
    directLinks = new HashMap<NodePortTuple, Set<Link>>();
    portBroadcastDomainLinks = new HashMap<NodePortTuple, Set<Link>>();
    tunnelPorts = new HashSet<NodePortTuple>();
    topologyAware = new ArrayList<ITopologyListener>();
    ldUpdates = new LinkedBlockingQueue<LDUpdate>();
    haListener = new HAListenerDelegate();
    registerTopologyDebugCounters();
    registerTopologyDebugEvents();
}
项目:fresco_floodlight    文件:LinkDiscoveryManagerTest.java   
@Test
public void testAddOrUpdateLink() throws Exception {
    LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager();
    U64 latency = U64.of(100);
    Link lt = new Link(DatapathId.of(1L), OFPort.of(2), DatapathId.of(2L), OFPort.of(1), latency);
    LinkInfo info = new LinkInfo(new Date(),
                                 new Date(), null);
    linkDiscovery.addOrUpdateLink(lt, info);

    NodePortTuple srcNpt = new NodePortTuple(DatapathId.of(1L), OFPort.of(2));
    NodePortTuple dstNpt = new NodePortTuple(DatapathId.of(2L), OFPort.of(1));

    // check invariants hold
    assertNotNull(linkDiscovery.switchLinks.get(lt.getSrc()));
    assertTrue(linkDiscovery.switchLinks.get(lt.getSrc()).contains(lt));
    assertNotNull(linkDiscovery.getPortLinks().get(srcNpt));
    assertTrue(linkDiscovery.getPortLinks().get(srcNpt).contains(lt));
    assertNotNull(linkDiscovery.portLinks.get(dstNpt));
    assertTrue(linkDiscovery.portLinks.get(dstNpt).contains(lt));
    assertTrue(linkDiscovery.links.containsKey(lt));
    assertTrue(linkDiscovery.switchLinks.get(lt.getSrc()).iterator().next().getLatency().equals(latency));
}
项目:open-kilda    文件:SwitchManager.java   
/**
 * Installs the verification rule
 *
 * @param dpid        datapathId of switch
 * @param isBroadcast if broadcast then set a generic match; else specific to switch Id
 * @return true if the command is accepted to be sent to switch, false otherwise - switch is disconnected or in
 * SLAVE mode
 */
private boolean installVerificationRule(final DatapathId dpid, final boolean isBroadcast) {
    IOFSwitch sw = ofSwitchService.getSwitch(dpid);

    Match match = matchVerification(sw, isBroadcast);
    ArrayList<OFAction> actionList = new ArrayList<>(2);
    actionList.add(actionSendToController(sw));
    actionList.add(actionSetDstMac(sw, dpidToMac(sw)));
    OFInstructionApplyActions instructionApplyActions = sw.getOFFactory().instructions()
            .applyActions(actionList).createBuilder().build();
    final long cookie = isBroadcast ? 0x8000000000000002L : 0x8000000000000003L;
    OFFlowMod flowMod = buildFlowMod(sw, match, null, instructionApplyActions,
            cookie, FlowModUtils.PRIORITY_VERY_HIGH);
    String flowname = (isBroadcast) ? "Broadcast" : "Unicast";
    flowname += "--VerificationFlow--" + dpid.toString();
    return pushFlow(flowname, dpid, flowMod);
}
项目:open-kilda    文件:SwitchEventCollector.java   
/**
 * {@inheritDoc}
 */
@Override
public void switchActivated(final DatapathId switchId) {
    final IOFSwitch sw = switchService.getSwitch(switchId);

    Message message = buildSwitchMessage(sw, SwitchState.ACTIVATED);
    kafkaProducer.postMessage(TOPO_EVENT_TOPIC, message);

    ImmutablePair<Long, Boolean> metersDeleted;
    metersDeleted = switchManager.deleteMeter(switchId, ALL_VAL);
    if (!metersDeleted.getRight()) {
        logger.error("Could not delete meters from switch={} xid={}", switchId, metersDeleted.getLeft());
    }

    boolean defaultRulesInstalled = switchManager.installDefaultRules(switchId);
    if (!defaultRulesInstalled) {
        logger.error("Could not install default rules on switch={}", switchId);
    }

    if (sw.getEnabledPortNumbers() != null) {
        for (OFPort p : sw.getEnabledPortNumbers()) {
            kafkaProducer.postMessage(TOPO_EVENT_TOPIC, buildPortMessage(sw.getId(), p, PortChangeType.UP));
        }
    }
}
项目:fresco_floodlight    文件:TopologyManager.java   
@Override
public boolean isAttachmentPointPort(DatapathId switchid, OFPort port, boolean tunnelEnabled) {

    // If the switch port is 'tun-bsn' port, it is not
    // an attachment point port, irrespective of whether
    // a link is found through it or not.
    if (linkDiscoveryService.isTunnelPort(switchid, port))
        return false;

    TopologyInstance ti = getCurrentInstance(tunnelEnabled);

    // if the port is not attachment point port according to
    // topology instance, then return false
    if (ti.isAttachmentPointPort(switchid, port) == false)
        return false;

    // Check whether the port is a physical port. We should not learn
    // attachment points on "special" ports.
    if ((port.getShortPortNumber() & 0xff00) == 0xff00 && port.getShortPortNumber() != (short)0xfffe) return false;

    // Make sure that the port is enabled.
    IOFSwitch sw = switchService.getActiveSwitch(switchid);
    if (sw == null) return false;
    return (sw.portEnabled(port));
}
项目: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    文件:TopologyInstance.java   
protected void calculateBroadcastPortMap(){
this.broadcastPortMap.clear();

for (DatapathId sw : this.switches) {
    for (OFPort p : this.allPorts.get(sw)){
        NodePortTuple npt = new NodePortTuple(sw, p);
        if (isEdge(sw, p) || broadcastNodePorts.contains(npt)) { 
            if (broadcastPortMap.containsKey(sw)) {
                    broadcastPortMap.get(sw).add(p);
                } else {
                    broadcastPortMap.put(sw, new HashSet<OFPort>(Arrays.asList(p)));
                }
        }           
    }
}
  }
项目:fresco_floodlight    文件:DeviceManagerImpl.java   
/**
 * Parse an entity from an {@link Ethernet} packet.
 * @param eth the packet to parse
 * @param sw the switch on which the packet arrived
 * @param pi the original packetin
 * @return the entity from the packet
 */
protected Entity getSourceEntityFromPacket(Ethernet eth, DatapathId swdpid, OFPort port) {
    MacAddress dlAddr = eth.getSourceMACAddress();

    // Ignore broadcast/multicast source
    if (dlAddr.isBroadcast() || dlAddr.isMulticast())
        return null;
    // Ignore 0 source mac
    if (dlAddr.getLong() == 0)
        return null;

    VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
    IPv4Address ipv4Src = getSrcIPv4AddrFromARP(eth, dlAddr);
    IPv6Address ipv6Src = ipv4Src.equals(IPv4Address.NONE) ? getSrcIPv6Addr(eth) : IPv6Address.NONE;
    return new Entity(dlAddr,
            vlan,
            ipv4Src,
            ipv6Src,
            swdpid,
            port,
            new Date());
}
项目:iTAP-controller    文件:DeviceManagerImplTest.java   
private static void
mockTopologyForPacketInTests(ITopologyService mockTopology) {
    expect(mockTopology.isAttachmentPointPort(DatapathId.of(anyLong()),
            OFPort.of(anyShort()))).
            andReturn(true).
            anyTimes();
    expect(mockTopology.isConsistent(DatapathId.of(EasyMock.anyLong()),
            OFPort.of(EasyMock.anyShort()),
            DatapathId.of(EasyMock.anyLong()),
            OFPort.of(EasyMock.anyShort()))).andReturn(false).
            anyTimes();
    expect(mockTopology.isBroadcastDomainPort(DatapathId.of(EasyMock.anyLong()),
            OFPort.of(EasyMock.anyShort())))
            .andReturn(false)
            .anyTimes();
    expect(mockTopology.getL2DomainId(DatapathId.of(anyLong()))).andReturn(DatapathId.of(1L)).anyTimes();
    expect(mockTopology.isInSameBroadcastDomain(DatapathId.of(anyLong()),
            OFPort.of(anyShort()),
            DatapathId.of(anyLong()),
            OFPort.of(anyShort())))
            .andReturn(false).anyTimes();

}
项目:iTAP-controller    文件:StaticFlowEntryPusher.java   
/**
 * Writes an OFFlowMod to a switch. It checks to make sure the switch
 * exists before it sends
 * @param dpid The data  to write the flow mod to
 * @param flowMod The OFFlowMod to write
 */
private void writeFlowModToSwitch(DatapathId dpid, OFFlowMod flowMod) {
    IOFSwitch ofSwitch = switchService.getSwitch(dpid);
    if (ofSwitch == null) {
        if (log.isDebugEnabled()) {
            log.debug("Not deleting key {} :: switch {} not connected", dpid.toString());
        }
        return;
    }
    writeFlowModToSwitch(ofSwitch, flowMod);
}
项目:fresco_floodlight    文件:StaticFlowEntryPusher.java   
/**
 * Writes a list of OFMessages to a switch
 * @param dpid The datapath ID of the switch to write to
 * @param messages The list of OFMessages to write.
 */
private void writeOFMessagesToSwitch(DatapathId dpid, List<OFMessage> messages) {
    IOFSwitch ofswitch = switchService.getSwitch(dpid);
    if (ofswitch != null) {  // is the switch connected
        if (log.isDebugEnabled()) {
            log.debug("Sending {} new entries to {}", messages.size(), dpid);
        }
        ofswitch.write(messages);
    }
}
项目:fresco_floodlight    文件:LinkDiscoveryManager.java   
/**
 * Remove a switch port from the suppressed LLDP list. Discover links on
 * that switchport.
 */
@Override
public void RemoveFromSuppressLLDPs(DatapathId sw, OFPort port) {
    NodePortTuple npt = new NodePortTuple(sw, port);
    this.suppressLinkDiscovery.remove(npt);
    discover(npt);
}
项目:iTAP-controller    文件:StaticFlowEntryPusher.java   
@Override
public void addFlow(String name, OFFlowMod fm, DatapathId swDpid) {
    try {
        Map<String, Object> fmMap = StaticFlowEntries.flowModToStorageEntry(fm, swDpid.toString(), name);
        storageSourceService.insertRowAsync(TABLE_NAME, fmMap);
    } catch (Exception e) {
        log.error("Error! Check the fields specified for the flow.Make sure IPv4 fields are not mixed with IPv6 fields or all "
                + "mandatory fields are specified. ");
    }
}
项目:fresco_floodlight    文件:DeviceManagerImpl.java   
@Override
public IDevice findDevice(@Nonnull MacAddress macAddress, VlanVid vlan,
        @Nonnull IPv4Address ipv4Address, @Nonnull IPv6Address ipv6Address,
        @Nonnull DatapathId switchDPID, @Nonnull OFPort switchPort)
                throws IllegalArgumentException {
    if (macAddress == null) {
        throw new IllegalArgumentException("MAC address cannot be null. Try MacAddress.NONE if intention is 'no MAC'");
    }
    if (ipv4Address == null) {
        throw new IllegalArgumentException("IPv4 address cannot be null. Try IPv4Address.NONE if intention is 'no IPv4'");
    }
    if (ipv6Address == null) {
        throw new IllegalArgumentException("IPv6 address cannot be null. Try IPv6Address.NONE if intention is 'no IPv6'");
    }
    if (vlan == null) {
        throw new IllegalArgumentException("VLAN cannot be null. Try VlanVid.ZERO if intention is 'no VLAN / untagged'");
    }
    if (switchDPID == null) {
        throw new IllegalArgumentException("Switch DPID cannot be null. Try DatapathId.NONE if intention is 'no DPID'");
    }
    if (switchPort == null) {
        throw new IllegalArgumentException("Switch port cannot be null. Try OFPort.ZERO if intention is 'no port'");
    }

    Entity e = new Entity(macAddress, vlan, 
            ipv4Address, ipv6Address, 
            switchDPID, switchPort, Entity.NO_DATE);

    /*
     * allKeyFieldsPresent() will check if the entity key fields (e.g. MAC and VLAN)
     * have non-"zero" values i.e. are not set to e.g. MacAddress.NONE and VlanVid.ZERO
     */
    if (!allKeyFieldsPresent(e, entityClassifier.getKeyFields())) {
        throw new IllegalArgumentException("Not all key fields specified."
                + " Required fields: " + entityClassifier.getKeyFields());
    }
    return findDeviceByEntity(e);
}
项目:fresco_floodlight    文件:DHCPSwitchFlowSetter.java   
@Override
public void switchAdded(DatapathId dpid) {
    /* Insert static flows on all ports of the switch to redirect
     * DHCP client --> DHCP DHCPServer traffic to the controller.
     * DHCP client's operate on UDP port 67
     */
    IOFSwitch sw = switchService.getSwitch(dpid);

    //fix concurrency flaw
    if (sw == null){
        return;
    }

    OFFlowAdd.Builder flow = sw.getOFFactory().buildFlowAdd();
    Match.Builder match = sw.getOFFactory().buildMatch();
    ArrayList<OFAction> actionList = new ArrayList<OFAction>();
    OFActionOutput.Builder action = sw.getOFFactory().actions().buildOutput();
    for (OFPortDesc port : sw.getPorts()) {
        match.setExact(MatchField.IN_PORT, port.getPortNo());
        match.setExact(MatchField.ETH_TYPE, EthType.IPv4);
        match.setExact(MatchField.IP_PROTO, IpProtocol.UDP);
        match.setExact(MatchField.UDP_SRC, UDP.DHCP_CLIENT_PORT);
        action.setMaxLen(0xffFFffFF);
        action.setPort(OFPort.CONTROLLER);
        actionList.add(action.build());

        flow.setBufferId(OFBufferId.NO_BUFFER);
        flow.setHardTimeout(0);
        flow.setIdleTimeout(0);
        flow.setOutPort(OFPort.CONTROLLER);
        flow.setActions(actionList);
        flow.setMatch(match.build());
        flow.setPriority(32767);
        sfp.addFlow("dhcp-port---" + port.getPortNo().getPortNumber() + "---(" + port.getName() + ")", flow.build(), sw.getId());
    }       
}
项目:iTAP-controller    文件:LinkDiscoveryManager.java   
/**
 * Add a switch port to the suppressed LLDP list. Remove any known links on
 * the switch port.
 */
@Override
public void AddToSuppressLLDPs(DatapathId sw, OFPort port) {
    NodePortTuple npt = new NodePortTuple(sw, port);
    this.suppressLinkDiscovery.add(npt);
    deleteLinksOnPort(npt, "LLDP suppressed.");
}
项目:fresco_floodlight    文件:TopologyInstanceTest.java   
protected void verifyClusters(int[][] clusters, boolean tunnelsEnabled) {
    List<DatapathId> verifiedSwitches = new ArrayList<DatapathId>();

    // Make sure the expected cluster arrays are sorted so we can
    // use binarySearch to test for membership
    for (int i = 0; i < clusters.length; i++)
        Arrays.sort(clusters[i]);

    TopologyInstance ti = 
            topologyManager.getCurrentInstance(tunnelsEnabled);
    Set<DatapathId> switches = ti.getSwitches();

    for (DatapathId sw: switches) {
        if (!verifiedSwitches.contains(sw)) {

            int[] expectedCluster = null;

            for (int j = 0; j < clusters.length; j++) {
                if (Arrays.binarySearch(clusters[j], (int)sw.getLong()) >= 0) {
                    expectedCluster = clusters[j];
                    break;
                }
            }
            if (expectedCluster != null) {
                Set<DatapathId> cluster = ti.getSwitchesInOpenflowDomain(sw);
                assertEquals(expectedCluster.length, cluster.size());
                for (DatapathId sw2: cluster) {
                    assertTrue(Arrays.binarySearch(expectedCluster, (int)sw2.getLong()) >= 0);
                    verifiedSwitches.add(sw2);
                }
            }
        }
    }
}
项目:fresco_floodlight    文件:ForwardingTest.java   
@Test
public void testForwardNoPath() throws Exception {
    learnDevices(DestDeviceToLearn.NONE);

    // Set no destination attachment point or route
    // expect no Flow-mod but expect the packet to be flooded

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    Set<OFPort> bcastPorts = new HashSet<OFPort>();
    bcastPorts.add(OFPort.of(10));

    // Reset mocks, trigger the packet in, and validate results
    reset(topology);
    expect(topology.getSwitchBroadcastPorts(DatapathId.of(1L))).andReturn(bcastPorts).once();
    expect(topology.isAttachmentPointPort(DatapathId.of(anyLong()),
            OFPort.of(anyShort())))
            .andReturn(true)
            .anyTimes();
    expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_FLOOD)).andReturn(true).anyTimes();
    expect(sw1.write(capture(wc1))).andReturn(true).once();
    replay(sw1, sw2, routingEngine, topology);
    forwarding.receive(sw1, this.packetIn, cntx);
    verify(sw1, sw2, routingEngine);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), packetOutFlooded));

    removeDeviceFromContext();
}
项目:fresco_floodlight    文件:TopologyManager.java   
@Override
public boolean isConsistent(DatapathId oldSw, OFPort oldPort,
        DatapathId newSw, OFPort newPort,
        boolean tunnelEnabled) {
    TopologyInstance ti = getCurrentInstance(tunnelEnabled);
    return ti.isConsistent(oldSw, oldPort, newSw, newPort);
}
项目:fresco_floodlight    文件:TopologyManager.java   
@Override
public NodePortTuple getIncomingSwitchPort(DatapathId src, OFPort srcPort,
        DatapathId dst, OFPort dstPort,
        boolean tunnelEnabled) {
    TopologyInstance ti = getCurrentInstance(tunnelEnabled);
    return ti.getIncomingSwitchPort(src, srcPort,
            dst, dstPort);
}
项目:open-kilda    文件:KafkaMessageCollector.java   
private void doDiscoverIslCommand(CommandData data) {
    DiscoverIslCommandData command = (DiscoverIslCommandData) data;
    logger.debug("sending discover ISL to {}", command);

    String switchId = command.getSwitchId();
    boolean result = pathVerificationService.sendDiscoveryMessage(
            DatapathId.of(switchId), OFPort.of(command.getPortNo()));

    if (result) {
        logger.debug("packet_out was sent to {}", switchId);
    } else {
        logger.warn("packet_out was not sent to {}", switchId);
    }
}
项目:open-kilda    文件:SwitchManagerTest.java   
@Before
public void setUp() throws FloodlightModuleException {
    ofSwitchService = createMock(IOFSwitchService.class);
    restApiService = createMock(IRestApiService.class);
    iofSwitch = createMock(IOFSwitch.class);
    switchDescription = createMock(SwitchDescription.class);
    dpid = createMock(DatapathId.class);

    context.addService(IRestApiService.class, restApiService);
    context.addService(IOFSwitchService.class, ofSwitchService);

    switchManager = new SwitchManager();
    switchManager.init(context);
}
项目:fresco_floodlight    文件:LinkDiscoveryManager.java   
/**
 * Add a switch port to the suppressed LLDP list. Remove any known links on
 * the switch port.
 */
@Override
public void AddToSuppressLLDPs(DatapathId sw, OFPort port) {
    NodePortTuple npt = new NodePortTuple(sw, port);
    this.suppressLinkDiscovery.add(npt);
    deleteLinksOnPort(npt, "LLDP suppressed.");
}
项目:iTAP-controller    文件:OFSwitchManager.java   
@Override
public synchronized void switchAdded(IOFSwitchBackend sw) {
    DatapathId dpid = sw.getId();
    IOFSwitchBackend oldSw = this.switches.put(dpid, sw);
    // Update event history
    evSwitch.newEventWithFlush(new SwitchEvent(dpid, "connected"));

    if (oldSw == sw)  {
        // Note == for object equality, not .equals for value
        counters.errorActivatedSwitchNotPresent.increment();
        log.error("Switch {} added twice?", sw);
        return;
    } else if (oldSw != null) {
        // This happens either when we have switches with duplicate
        // DPIDs or when a switch reconnects before we saw the
        // disconnect
        counters.switchWithSameDpidActivated.increment();
        log.warn("New switch added {} for already-added switch {}", sw, oldSw);
        // We need to disconnect and remove the old switch
        // TODO: we notify switch listeners that the switch has been
        // removed and then we notify them that the new one has been
        // added. One could argue that a switchChanged notification
        // might be more appropriate in this case....
        oldSw.cancelAllPendingRequests();
        addUpdateToQueue(new SwitchUpdate(dpid, SwitchUpdateType.REMOVED));
        oldSw.disconnect();
    }

}
项目:fresco_floodlight    文件:MockEntityClassifierMac.java   
@Override
public IEntityClass classifyEntity(Entity entity) {
    if (entity.getSwitchDPID() == null) {
        throw new IllegalArgumentException("Not all key fields specified."
                + " Required fields: " + getKeyFields());
    } else if (entity.getSwitchDPID().equals(DatapathId.of(1))) {
        return testECMac1;
    } else if (entity.getSwitchDPID().equals(DatapathId.of(2))) {
        return testECMac2;
    } else if (entity.getSwitchDPID().equals(DatapathId.of(-1))) {
        return null;
    }
    return DefaultEntityClassifier.entityClass;
}
项目:fresco_floodlight    文件:TopologyManager.java   
@Override
public NodePortTuple
getAllowedIncomingBroadcastPort(DatapathId src, OFPort srcPort,
        boolean tunnelEnabled) {
    TopologyInstance ti = getCurrentInstance(tunnelEnabled);
    return ti.getAllowedIncomingBroadcastPort(src,srcPort);
}
项目:fresco_floodlight    文件:SecurityKernel.java   
private FlowAlias getFlowAlias(DatapathId dpid, long key){
    HashMap<Long, FlowAlias> faList = cMap.get(dpid);

    if (faList != null){
        return faList.get(key);
    }
    return null;
}
项目:fresco_floodlight    文件:VirtualNetworkFilterTest.java   
@Test
public void testDefaultGateway() {
    testAddHost();
    IOFMessageListener listener = getVirtualNetworkListener();
    cntx = new FloodlightContext();
    IFloodlightProviderService.bcStore.put(cntx,
                       IFloodlightProviderService.CONTEXT_PI_PAYLOAD,
                           (Ethernet)mac1ToGwPacketIntestPacket);
    deviceService.learnEntity(((Ethernet)mac1ToGwPacketIntestPacket).getDestinationMACAddress(),
            VlanVid.ZERO, IPv4Address.of(gw1), IPv6Address.NONE, DatapathId.NONE, OFPort.ZERO);
    Command ret = listener.receive(sw1, mac1ToGwPacketIn, cntx);
    assertTrue(ret == Command.CONTINUE);
}
项目:fresco_floodlight    文件:LinkDiscoveryManager.java   
private void handlePortDown(DatapathId switchId, OFPort portNumber) {
    NodePortTuple npt = new NodePortTuple(switchId, portNumber);
    deleteLinksOnPort(npt, "Port Status Changed");
    LDUpdate update = new LDUpdate(switchId, portNumber,
            UpdateOperation.PORT_DOWN);
    updates.add(update);
}
项目:fresco_floodlight    文件:LinkDiscoveryManager.java   
/**
 * Check if incoming discovery messages are enabled or not.
 * @param sw
 * @param port
 * @param isStandard
 * @return
 */
protected boolean isIncomingDiscoveryAllowed(DatapathId sw, OFPort port,
        boolean isStandard) {

    if (isLinkDiscoverySuppressed(sw, port)) {
        /* Do not process LLDPs from this port as suppressLLDP is set */
        return false;
    }

    IOFSwitch iofSwitch = switchService.getSwitch(sw);
    if (iofSwitch == null) {
        return false;
    }

    if (port == OFPort.LOCAL) return false;

    OFPortDesc ofpPort = iofSwitch.getPort(port);
    if (ofpPort == null) {
        if (log.isTraceEnabled()) {
            log.trace("Null physical port. sw={}, port={}",
                    sw.toString(), port.getPortNumber());
        }
        return false;
    }

    return true;
}
项目:iTAP-controller    文件:OFSwitchManager.java   
@Override
public void addSwitchEvent(DatapathId dpid, String reason, boolean flushNow) {
    if (flushNow)
        evSwitch.newEventWithFlush(new SwitchEvent(dpid, reason));
    else
        evSwitch.newEventNoFlush(new SwitchEvent(dpid, reason));
}
项目:fresco_floodlight    文件:OFConnectionTest.java   
@Before
public void setUp() throws Exception {
    factory = OFFactories.getFactory(OFVersion.OF_13);
    switchId = DatapathId.of(1);
    timer = new HashedWheelTimer();
    channel = EasyMock.createMock(Channel.class);        
    IDebugCounterService debugCounterService = new DebugCounterServiceImpl();
    debugCounterService.registerModule(OFConnectionCounters.COUNTER_MODULE);
    conn = new OFConnection(switchId, factory, channel, OFAuxId.MAIN,
                            debugCounterService, timer);
    eventLoop = new TestEventLoop();

    expect(channel.eventLoop()).andReturn(eventLoop).anyTimes();
}
项目:fresco_floodlight    文件:MockSwitchManager.java   
@Override
public List<SwitchRepresentation> getSwitchRepresentations() {
    List<SwitchRepresentation> representations = new ArrayList<SwitchRepresentation>();

    for(DatapathId dpid : this.switches.keySet()) {
        SwitchRepresentation representation = getSwitchRepresentation(dpid);
        if(representation != null) {
            representations.add(representation);
        }
    }
    return representations;
}
项目:fresco_floodlight    文件:TopologyManager.java   
@Override
public boolean isIncomingBroadcastAllowed(DatapathId sw, OFPort portId) {
    return isIncomingBroadcastAllowed(sw, portId, true);
}
项目:iTAP-controller    文件:BroadcastTree.java   
public BroadcastTree(HashMap<DatapathId, Link> links, HashMap<DatapathId, Integer> costs) {
    this.links = links;
    this.costs = costs;
}
项目:fresco_floodlight    文件:OFSwitchManager.java   
@Override
public IOFSwitch getSwitch(DatapathId dpid) {
    return this.switches.get(dpid);
}
项目:fresco_floodlight    文件:TopologyManager.java   
@Override
public NodePortTuple getIncomingSwitchPort(DatapathId src, OFPort srcPort,
        DatapathId dst, OFPort dstPort) {
    return getIncomingSwitchPort(src, srcPort, dst, dstPort, true);
}