Java 类org.projectfloodlight.openflow.protocol.OFFactory 实例源码

项目:open-kilda    文件:SwitchManager.java   
/**
 * {@inheritDoc}
 */
@Override
public OFMeterConfigStatsReply dumpMeters(final DatapathId dpid) {
    OFMeterConfigStatsReply values = null;
    IOFSwitch sw = ofSwitchService.getSwitch(dpid);
    if (sw == null) {
        throw new IllegalArgumentException(String.format("Switch %s was not found", dpid.toString()));
    }

    OFFactory ofFactory = sw.getOFFactory();
    OFMeterConfigStatsRequest meterRequest = ofFactory.buildMeterConfigStatsRequest()
            .setMeterId(0xffffffff)
            .build();

    try {
        ListenableFuture<OFMeterConfigStatsReply> future = sw.writeRequest(meterRequest);
        values = future.get(5, TimeUnit.SECONDS);
    } catch (ExecutionException | InterruptedException | TimeoutException e) {
        logger.error("Could not get meter config stats: {}", e.getMessage());
    }

    return values;
}
项目:open-kilda    文件:SwitchManager.java   
private ImmutablePair<Long, Boolean> installLegacyMeter(final IOFSwitch sw, final DatapathId dpid,
                                                        final long bandwidth, final long burstSize,
                                                        final long meterId) {
    logger.debug("installing legacy meter {} on OVS switch {} width bandwidth {}", meterId, dpid, bandwidth);

    Set<OFLegacyMeterFlags> flags = new HashSet<>(Arrays.asList(OFLegacyMeterFlags.KBPS, OFLegacyMeterFlags.BURST));
    OFFactory ofFactory = sw.getOFFactory();

    OFLegacyMeterBandDrop.Builder bandBuilder = ofFactory.legacyMeterBandDrop(bandwidth, burstSize).createBuilder();

    OFLegacyMeterMod meterMod = ofFactory.buildLegacyMeterMod()
            .setMeterId(meterId)
            .setCommand(OFLegacyMeterModCommand.ADD)
            .setMeters(singletonList(bandBuilder.build()))
            .setFlags(flags)
            .build();

    boolean response = sw.write(meterMod);
    return new ImmutablePair<>(meterMod.getXid(), response);
}
项目:open-kilda    文件:SwitchManager.java   
public ImmutablePair<Long, Boolean> deleteMeter(IOFSwitch sw, final DatapathId dpid, final long meterId) {
    logger.debug("deleting meter {} from switch {}", meterId, dpid);

    OFFactory ofFactory = sw.getOFFactory();

    OFMeterMod.Builder meterDeleteBuilder = ofFactory.buildMeterMod()
            .setMeterId(meterId)
            .setCommand(OFMeterModCommand.DELETE);

    if (sw.getOFFactory().getVersion().compareTo(OF_13) > 0) {
        meterDeleteBuilder.setBands(emptyList());
    } else {
        meterDeleteBuilder.setMeters(emptyList());
    }

    OFMeterMod meterDelete = meterDeleteBuilder.build();

    boolean response = sw.write(meterDelete);
    return new ImmutablePair<>(meterDelete.getXid(), response);
}
项目:open-kilda    文件:SwitchManager.java   
/**
 * Create an OFAction to change the outer most vlan.
 *
 * @param sw      switch object
 * @param newVlan final VLAN to be set on the packet
 * @return {@link OFAction}
 */
private OFAction actionReplaceVlan(final IOFSwitch sw, final int newVlan) {
    OFFactory factory = sw.getOFFactory();
    OFOxms oxms = factory.oxms();
    OFActions actions = factory.actions();

    if (OF_12.compareTo(factory.getVersion()) == 0) {
        return actions.buildSetField().setField(oxms.buildVlanVid()
                .setValue(OFVlanVidMatch.ofRawVid((short) newVlan))
                .build()).build();
    } else {
        return actions.buildSetField().setField(oxms.buildVlanVid()
                .setValue(OFVlanVidMatch.ofVlan(newVlan))
                .build()).build();
    }
}
项目:open-kilda    文件:PacketFactory.java   
/**
 * Generates a DHCP request OFPacketIn.
 * @param hostMac The host MAC address of for the request.
 * @return An OFPacketIn that contains a DHCP request packet.
 */
public static OFPacketIn DhcpDiscoveryRequestOFPacketIn(IOFSwitch sw,
        MacAddress hostMac) {
    byte[] serializedPacket = DhcpDiscoveryRequestEthernet(hostMac).serialize();
    OFFactory factory = sw.getOFFactory();
    OFPacketIn.Builder packetInBuilder = factory.buildPacketIn();
    if (factory.getVersion() == OFVersion.OF_10) {
        packetInBuilder
            .setInPort(OFPort.of(1))
            .setData(serializedPacket)
            .setReason(OFPacketInReason.NO_MATCH);
    } else {
        packetInBuilder
        .setMatch(factory.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).build())
        .setData(serializedPacket)
        .setReason(OFPacketInReason.NO_MATCH);
    }
    return packetInBuilder.build();
}
项目:athena    文件:OfdpaExtensionSelectorInterpreter.java   
@Override
public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) {
    ExtensionSelectorType type = extensionSelector.type();
    if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) {
        VlanId vlanId = ((OfdpaMatchVlanVid) extensionSelector).vlanId();
        // Special VLAN 0x0000/0x1FFF required by OFDPA
        if (vlanId.equals(VlanId.NONE)) {
            OFVlanVidMatch vid = OFVlanVidMatch.ofRawVid((short) 0x0000);
            OFVlanVidMatch mask = OFVlanVidMatch.ofRawVid((short) 0x1FFF);
            return factory.oxms().vlanVidMasked(vid, mask);
        // Normal case
        } else if (vlanId.equals(VlanId.ANY)) {
            return factory.oxms().vlanVidMasked(OFVlanVidMatch.PRESENT, OFVlanVidMatch.PRESENT);
        } else {
            return factory.oxms().vlanVid(OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vlanId.toShort())));
        }
    }
    throw new UnsupportedOperationException(
            "Unexpected ExtensionSelector: " + extensionSelector.toString());
}
项目:athena    文件:OFChannelHandler.java   
void processOFEchoRequest(OFChannelHandler h, OFEchoRequest m)
        throws IOException {
    if (h.ofVersion == null) {
        log.error("No OF version set for {}. Not sending Echo REPLY",
                h.channel.getRemoteAddress());
        return;
    }
    OFFactory factory = (h.ofVersion == OFVersion.OF_13) ?
            h.controller.getOFMessageFactory13() : h.controller.getOFMessageFactory10();
            OFEchoReply reply = factory
                    .buildEchoReply()
                    .setXid(m.getXid())
                    .setData(m.getData())
                    .build();
            h.channel.write(Collections.singletonList(reply));
}
项目:fresco_floodlight    文件:SwitchSyncRepresentation.java   
@JsonIgnore
public OFFeaturesReply getFeaturesReply(OFFactory factory) {
    /**
     * FIXME Icky work around; if a null actions got written to storage
     * then fake up an empty one so the builder() doesn't throw
     * a NPE.  Need to root cause why someone would write a null actions.
     * This code will all be removed shortly -- needed to unblock BVS team.
     */
    Set<OFActionType> workAroundActions;
    if (actions != null)
        workAroundActions = actions;
    else
        workAroundActions = Collections.<OFActionType> emptySet();

    OFFeaturesReply featuresReply = factory.buildFeaturesReply()
            .setXid(0)
            .setDatapathId(dpid)
            .setNBuffers(buffers)
            .setNTables(tables)
            .setCapabilities(capabilities)
            .setActions(workAroundActions)
            .setPorts(toOFPortDescList(factory, ports))
            .build();
    return featuresReply;
}
项目:fresco_floodlight    文件:OFChannelInitializer.java   
public OFChannelInitializer(IOFSwitchManager switchManager,
        INewOFConnectionListener connectionListener,
        IDebugCounterService debugCounters,
        Timer timer,
        List<U32> ofBitmaps,
        OFFactory defaultFactory,
        String keyStore, 
        String keyStorePassword) {
    super();
    this.switchManager = switchManager;
    this.connectionListener = connectionListener;
    this.timer = timer;
    this.debugCounters = debugCounters;
    this.defaultFactory = defaultFactory;
    this.ofBitmaps = ofBitmaps;
    this.keyStore = keyStore;
    this.keyStorePassword = keyStorePassword;
}
项目:fresco_floodlight    文件:OFConnection.java   
public OFConnection(@Nonnull DatapathId dpid,
        @Nonnull OFFactory factory,
        @Nonnull Channel channel,
        @Nonnull OFAuxId auxId,
        @Nonnull IDebugCounterService debugCounters,
        @Nonnull Timer timer) {
    Preconditions.checkNotNull(dpid, "dpid");
    Preconditions.checkNotNull(factory, "factory");
    Preconditions.checkNotNull(channel, "channel");
    Preconditions.checkNotNull(timer, "timer");
    Preconditions.checkNotNull(debugCounters);

    this.listener = NullConnectionListener.INSTANCE;
    this.dpid = dpid;
    this.factory = factory;
    this.channel = channel;
    this.auxId = auxId;
    this.connectedSince = new Date();
    this.xidDeliverableMap = new ConcurrentHashMap<>();
    this.counters = new OFConnectionCounters(debugCounters, dpid, this.auxId);
    this.timer = timer;
    this.latency = U64.ZERO;
}
项目:fresco_floodlight    文件:OFChannelHandler.java   
/**
 * Creates a handler for interacting with the switch channel
 *
 * @param controller
 *            the controller
 * @param newConnectionListener
 *            the class that listens for new OF connections (switchManager)
 * @param pipeline
 *            the channel pipeline
 * @param threadPool
 *            the thread pool
 * @param idleTimer
 *            the hash wheeled timer used to send idle messages (echo).
 *            passed to constructor to modify in case of aux connection.
 * @param debugCounters
 */
OFChannelHandler(@Nonnull IOFSwitchManager switchManager,
        @Nonnull INewOFConnectionListener newConnectionListener,
        @Nonnull ChannelPipeline pipeline,
        @Nonnull IDebugCounterService debugCounters,
        @Nonnull Timer timer,
        @Nonnull List<U32> ofBitmaps,
        @Nonnull OFFactory defaultFactory) {

    Preconditions.checkNotNull(switchManager, "switchManager");
    Preconditions.checkNotNull(newConnectionListener, "connectionOpenedListener");
    Preconditions.checkNotNull(pipeline, "pipeline");
    Preconditions.checkNotNull(timer, "timer");
    Preconditions.checkNotNull(debugCounters, "debugCounters");

    this.pipeline = pipeline;
    this.debugCounters = debugCounters;
    this.newConnectionListener = newConnectionListener;
    this.counters = switchManager.getCounters();
    this.state = new InitState();
    this.timer = timer;
    this.ofBitmaps = ofBitmaps;
    this.factory = defaultFactory;

    log.debug("constructor on OFChannelHandler {}", String.format("%08x", System.identityHashCode(this)));
}
项目:fresco_floodlight    文件:OFSwitchManager.java   
/**
 * Find the max version supplied in the supported
 * versions list and use it as the default, which
 * will subsequently be used in our hello message
 * header's version field.
 * 
 * The factory can be later "downgraded" to a lower
 * version depending on what's computed during the
 * version-negotiation part of the handshake.
 * 
 * Assumption: The Set of OFVersion ofVersions
 * variable has been set already and is NOT EMPTY.
 * 
 * @return the highest-version OFFactory we support
 */
private OFFactory computeInitialFactory(Set<OFVersion> ofVersions) {
    /* This should NEVER happen. Double-checking. */
    if (ofVersions == null || ofVersions.isEmpty()) {
        throw new IllegalStateException("OpenFlow version list should never be null or empty at this point. Make sure it's set in the OFSwitchManager.");
    }
    OFVersion highest = null;
    for (OFVersion v : ofVersions) {
        if (highest == null) {
            highest = v;
        } else if (v.compareTo(highest) > 0) {
            highest = v;
        }
    }
    /* 
     * This assumes highest != null, which
     * it won't be if the list of versions
     * is not empty.
     */
    return OFFactories.getFactory(highest);
}
项目:fresco_floodlight    文件:PacketFactory.java   
/**
 * Generates a DHCP request OFPacketIn.
 * @param hostMac The host MAC address of for the request.
 * @return An OFPacketIn that contains a DHCP request packet.
 */
public static OFPacketIn DhcpDiscoveryRequestOFPacketIn(IOFSwitch sw,
        MacAddress hostMac) {
    byte[] serializedPacket = DhcpDiscoveryRequestEthernet(hostMac).serialize();
    OFFactory factory = sw.getOFFactory();
    OFPacketIn.Builder packetInBuilder = factory.buildPacketIn();
    if (factory.getVersion() == OFVersion.OF_10) {
        packetInBuilder
            .setInPort(OFPort.of(1))
            .setData(serializedPacket)
            .setReason(OFPacketInReason.NO_MATCH);
    } else {
        packetInBuilder
        .setMatch(factory.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).build())
        .setData(serializedPacket)
        .setReason(OFPacketInReason.NO_MATCH);
    }
    return packetInBuilder.build();
}
项目:iTAP-controller    文件:OFConnection.java   
public OFConnection(@Nonnull DatapathId dpid,
                    @Nonnull OFFactory factory,
                    @Nonnull Channel channel,
                    @Nonnull OFAuxId auxId,
                    @Nonnull IDebugCounterService debugCounters,
                    @Nonnull Timer timer) {
    Preconditions.checkNotNull(dpid, "dpid");
    Preconditions.checkNotNull(factory, "factory");
    Preconditions.checkNotNull(channel, "channel");
    Preconditions.checkNotNull(timer, "timer");
    Preconditions.checkNotNull(debugCounters);

    this.listener = NullConnectionListener.INSTANCE;
    this.dpid = dpid;
    this.factory = factory;
    this.channel = channel;
    this.auxId = auxId;
    this.connectedSince = new Date();
    this.xidDeliverableMap = new ConcurrentHashMap<>();
    this.counters = new OFConnectionCounters(debugCounters, dpid, this.auxId);
    this.timer = timer;
}
项目:iTAP-controller    文件:SwitchSyncRepresentation.java   
@JsonIgnore
public OFFeaturesReply getFeaturesReply(OFFactory factory) {
    /**
     * FIXME Icky work around; if a null actions got written to storage
     * then fake up an empty one so the builder() doesn't throw
     * a NPE.  Need to root cause why someone would write a null actions.
     * This code will all be removed shortly -- needed to unblock BVS team.
     */
    Set<OFActionType> workAroundActions;
    if (actions != null)
        workAroundActions = actions;
    else
        workAroundActions = Collections.<OFActionType> emptySet();

    OFFeaturesReply featuresReply = factory.buildFeaturesReply()
            .setXid(0)
            .setDatapathId(dpid)
            .setNBuffers(buffers)
            .setNTables(tables)
            .setCapabilities(capabilities)
            .setActions(workAroundActions)
            .setPorts(toOFPortDescList(factory, ports))
            .build();
    return featuresReply;
}
项目:iTAP-controller    文件:PacketFactory.java   
/**
 * Generates a DHCP request OFPacketIn.
 * @param hostMac The host MAC address of for the request.
 * @return An OFPacketIn that contains a DHCP request packet.
 */
public static OFPacketIn DhcpDiscoveryRequestOFPacketIn(IOFSwitch sw,
        MacAddress hostMac) {
    byte[] serializedPacket = DhcpDiscoveryRequestEthernet(hostMac).serialize();
    OFFactory factory = sw.getOFFactory();
    OFPacketIn.Builder packetInBuilder = factory.buildPacketIn();
    if (factory.getVersion() == OFVersion.OF_10) {
        packetInBuilder
            .setInPort(OFPort.of(1))
            .setData(serializedPacket)
            .setReason(OFPacketInReason.NO_MATCH);
    } else {
        packetInBuilder
        .setMatch(factory.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).build())
        .setData(serializedPacket)
        .setReason(OFPacketInReason.NO_MATCH);
    }
    return packetInBuilder.build();
}
项目:open-kilda    文件:SwitchManager.java   
/**
 * {@inheritDoc}
 */
@Override
public OFFlowStatsReply dumpFlowTable(final DatapathId dpid) {
    OFFlowStatsReply values = null;
    IOFSwitch sw = ofSwitchService.getSwitch(dpid);
    if (sw == null) {
        throw new IllegalArgumentException(String.format("Switch %s was not found", dpid.toString()));
    }

    OFFactory ofFactory = sw.getOFFactory();
    OFFlowStatsRequest flowRequest = ofFactory.buildFlowStatsRequest()
            .setMatch(sw.getOFFactory().matchWildcardAll())
            .setTableId(TableId.ALL)
            .setOutPort(OFPort.ANY)
            .setOutGroup(OFGroup.ANY)
            .setCookieMask(U64.ZERO)
            .build();

    try {
        ListenableFuture<OFFlowStatsReply> future = sw.writeRequest(flowRequest);
        values = future.get(10, TimeUnit.SECONDS);
    } catch (ExecutionException | InterruptedException | TimeoutException e) {
        logger.error("Could not get flow stats: {}", e.getMessage());
    }

    return values;
}
项目:open-kilda    文件:SwitchManager.java   
private ImmutablePair<Long, Boolean> installMeter(final IOFSwitch sw, final DatapathId dpid, final long bandwidth,
                                                 final long burstSize, final long meterId) {
    logger.debug("installing meter {} on switch {} width bandwidth {}", meterId, dpid, bandwidth);

    Set<OFMeterFlags> flags = new HashSet<>(Arrays.asList(OFMeterFlags.KBPS, OFMeterFlags.BURST));
    OFFactory ofFactory = sw.getOFFactory();

    OFMeterBandDrop.Builder bandBuilder = ofFactory.meterBands()
            .buildDrop()
            .setRate(bandwidth)
            .setBurstSize(burstSize);

    OFMeterMod.Builder meterModBuilder = ofFactory.buildMeterMod()
            .setMeterId(meterId)
            .setCommand(OFMeterModCommand.ADD)
            .setFlags(flags);

    if (sw.getOFFactory().getVersion().compareTo(OF_13) > 0) {
        meterModBuilder.setBands(singletonList(bandBuilder.build()));
    } else {
        meterModBuilder.setMeters(singletonList(bandBuilder.build()));
    }

    OFMeterMod meterMod = meterModBuilder.build();

    boolean response = sw.write(meterMod);
    return new ImmutablePair<>(meterMod.getXid(), response);
}
项目:open-kilda    文件:SwitchManager.java   
/**
 * {@inheritDoc}
 */
@Override
public ImmutablePair<Long, Boolean> deleteFlow(final DatapathId dpid, final String flowId, final Long cookie) {
    logger.info("deleting flows {} from switch {}", flowId, dpid.toString());

    IOFSwitch sw = ofSwitchService.getSwitch(dpid);
    OFFactory ofFactory = sw.getOFFactory();
    OFFlowDelete flowDelete = ofFactory.buildFlowDelete()
            .setCookie(U64.of(cookie))
            .setCookieMask(NON_SYSTEM_MASK)
            .build();

    boolean response = sw.write(flowDelete);
    return new ImmutablePair<>(flowDelete.getXid(), response);
}
项目:open-kilda    文件:SwitchManager.java   
public ImmutablePair<Long, Boolean> deleteLegacyMeter(final IOFSwitch sw, final DatapathId dpid, final long meterId) {
    logger.debug("deleting legacy meter {} from switch {}", meterId, dpid);

    OFFactory ofFactory = sw.getOFFactory();

    OFLegacyMeterMod meterDelete = ofFactory.buildLegacyMeterMod()
            .setMeterId(meterId)
            .setMeters(emptyList())
            .setCommand(OFLegacyMeterModCommand.DELETE)
            .build();

    boolean response = sw.write(meterDelete);
    return new ImmutablePair<>(meterDelete.getXid(), response);
}
项目:open-kilda    文件:FloodlightTestCase.java   
public IOFSwitch buildMockIOFSwitch(Long id, OFPortDesc portDesc, OFFactory factory,
        OFDescStatsReply swDesc, InetSocketAddress inetAddr) {
    IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
    expect(sw.getId()).andReturn(DatapathId.of(id)).anyTimes();
    expect(sw.getPort(OFPort.of(1))).andReturn(portDesc).anyTimes();
    expect(sw.getOFFactory()).andReturn(factory).anyTimes();
    expect(sw.getBuffers()).andReturn(swFeatures.getNBuffers()).anyTimes();
    expect(sw.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_TABLE)).andReturn(true).anyTimes();
    expect(sw.getSwitchDescription()).andReturn(new SwitchDescription(swDesc)).anyTimes();
    expect(sw.isActive()).andReturn(true).anyTimes();
    expect(sw.getLatency()).andReturn(U64.of(10L)).anyTimes();
    expect(sw.getInetAddress()).andReturn(inetAddr).anyTimes();
    return sw;
}
项目:open-kilda    文件:MockSwitchManager.java   
@Override
public IOFSwitchBackend
        getOFSwitchInstance(IOFConnectionBackend connection,
                            SwitchDescription description,
                            OFFactory factory, DatapathId datapathId) {
    return null;
}
项目:athena    文件:NiciraExtensionSelectorInterpreter.java   
@Override
public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) {
    ExtensionSelectorType type = extensionSelector.type();

    if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type())) {
        NiciraMatchNshSpi niciraNshSpi = (NiciraMatchNshSpi) extensionSelector;
        return factory.oxms().nsp(U32.of(niciraNshSpi.nshSpi().servicePathId()));
    }
    if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) {
        NiciraMatchNshSi niciraNshSi = (NiciraMatchNshSi) extensionSelector;
        return factory.oxms().nsi(U8.of(niciraNshSi.nshSi().serviceIndex()));
    }
    if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE.type())) {
        NiciraMatchEncapEthType niciraEncapEthType = (NiciraMatchEncapEthType) extensionSelector;
        return factory.oxms().encapEthType(U16.of(niciraEncapEthType.encapEthType()));
    }
    if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type())) {
        // TODO
    }
    if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH2.type())) {
        // TODO
    }
    if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH3.type())) {
        // TODO
    }
    if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH4.type())) {
        // TODO
    }
    return null;
}
项目:athena    文件:OfdpaExtensionTreatmentInterpreter.java   
@Override
public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) {
    ExtensionTreatmentType type = extensionTreatment.type();
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) {
        VlanId vlanId = ((OfdpaSetVlanVid) extensionTreatment).vlanId();
        // NOTE: OFDPA requires isPresent bit set to zero.
        OFVlanVidMatch match = OFVlanVidMatch.ofRawVid(vlanId.toShort());
        return factory.actions().setField(factory.oxms().vlanVid(match));
    }
    throw new UnsupportedOperationException(
            "Unexpected ExtensionTreatment: " + extensionTreatment.toString());
}
项目:athena    文件:OFChannelHandler.java   
@Override
public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e)
        throws Exception {
    OFFactory factory = (ofVersion == OFVersion.OF_13) ? factory13 : factory10;
    OFMessage m = factory.buildEchoRequest().build();
    log.debug("Sending Echo Request on idle channel: {}",
            e.getChannel().getPipeline().getLast().toString());
    e.getChannel().write(Collections.singletonList(m));
    // XXX S some problems here -- echo request has no transaction id, and
    // echo reply is not correlated to the echo request.
}
项目:athena    文件:OFChannelHandler.java   
/**
 * Send featuresRequest msg to the switch using the handshake transactions ids.
 * @throws IOException
 */
private void sendHandshakeFeaturesRequestMessage() throws IOException {
    OFFactory factory = (ofVersion == OFVersion.OF_13) ? factory13 : factory10;
    OFMessage m = factory.buildFeaturesRequest()
            .setXid(this.handshakeTransactionIds--)
            .build();
    channel.write(Collections.singletonList(m));
}
项目:athena    文件:OFChannelHandler.java   
/**
    * Send the configuration requests to tell the switch we want full
    * packets.
    * @throws IOException
    */
   private void sendHandshakeSetConfig() throws IOException {
       OFFactory factory = (ofVersion == OFVersion.OF_13) ? factory13 : factory10;
       //log.debug("Sending CONFIG_REQUEST to {}", channel.getRemoteAddress());
       List<OFMessage> msglist = new ArrayList<OFMessage>(3);

       // Ensure we receive the full packet via PacketIn
       // FIXME: We don't set the reassembly flags.
// Only send config to switches to send full packets, if they have a buffer.
       // Saves a packet & OFSetConfig can't be handled by certain switches.
       if(this.featuresReply.getNBuffers() > 0) {
           OFSetConfig sc = factory
                   .buildSetConfig()
                   .setMissSendLen((short) 0xffff)
                   .setXid(this.handshakeTransactionIds--)
                   .build();
           msglist.add(sc);
       }

       // Barrier
       OFBarrierRequest br = factory
               .buildBarrierRequest()
               .setXid(this.handshakeTransactionIds--)
               .build();
       msglist.add(br);

       // Verify (need barrier?)
       OFGetConfigRequest gcr = factory
               .buildGetConfigRequest()
               .setXid(this.handshakeTransactionIds--)
               .build();
       msglist.add(gcr);
       channel.write(msglist);
   }
项目:athena    文件:OFChannelHandler.java   
/**
 * send a description state request.
 * @throws IOException
 */
private void sendHandshakeDescriptionStatsRequest() throws IOException {
    // Get Description to set switch-specific flags
    OFFactory factory = (ofVersion == OFVersion.OF_13) ? factory13 : factory10;
    OFDescStatsRequest dreq = factory
            .buildDescStatsRequest()
            .setXid(handshakeTransactionIds--)
            .build();
    channel.write(Collections.singletonList(dreq));
}
项目:athena    文件:OpenFlowDeviceProvider.java   
@Override
public void triggerProbe(DeviceId deviceId) {
    LOG.debug("Triggering probe on device {}", deviceId);

    final Dpid dpid = dpid(deviceId.uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    if (sw == null || !sw.isConnected()) {
        LOG.error("Failed to probe device {} on sw={}", deviceId, sw);
        providerService.deviceDisconnected(deviceId);
        return;
    } else {
        LOG.trace("Confirmed device {} connection", deviceId);
    }

    // Prompt an update of port information. We can use any XID for this.
    OFFactory fact = sw.factory();
    switch (fact.getVersion()) {
        case OF_10:
            sw.sendMsg(fact.buildFeaturesRequest().setXid(0).build());
            break;
        case OF_13:
            sw.sendMsg(fact.buildPortDescStatsRequest().setXid(0).build());
            break;
        default:
            LOG.warn("Unhandled protocol version");
    }
}
项目:athena    文件:FlowModBuilder.java   
/**
 * Creates a new flow mod builder.
 *
 * @param flowRule the flow rule to transform into a flow mod
 * @param factory the OpenFlow factory to use to build the flow mod
 * @param xid the transaction ID
 * @param driverService the device driver service
 * @return the new flow mod builder
 */
public static FlowModBuilder builder(FlowRule flowRule,
                                     OFFactory factory,
                                     Optional<Long> xid,
                                     Optional<DriverService> driverService) {
    switch (factory.getVersion()) {
    case OF_10:
        return new FlowModBuilderVer10(flowRule, factory, xid, driverService);
    case OF_13:
        return new FlowModBuilderVer13(flowRule, factory, xid, driverService);
    default:
        throw new UnsupportedOperationException(
                "No flow mod builder for protocol version " + factory.getVersion());
    }
}
项目:athena    文件:FlowModBuilder.java   
/**
 * Constructs a flow mod builder.
 *
 * @param flowRule the flow rule to transform into a flow mod
 * @param factory the OpenFlow factory to use to build the flow mod
 * @param driverService the device driver service
 * @param xid the transaction ID
 */
protected FlowModBuilder(FlowRule flowRule, OFFactory factory, Optional<Long> xid,
                         Optional<DriverService> driverService) {
    this.factory = factory;
    this.flowRule = flowRule;
    this.selector = flowRule.selector();
    this.xid = xid.orElse(0L);
    this.driverService = driverService;
    this.deviceId = flowRule.deviceId();
}
项目:athena    文件:GroupModBuilder.java   
private GroupModBuilder(GroupBuckets buckets, GroupId groupId,
                         GroupDescription.Type type, OFFactory factory,
                         Optional<Long> xid) {
    this.buckets = buckets;
    this.groupId = groupId;
    this.type = type;
    this.factory = factory;
    this.xid = xid.orElse((long) 0);
}
项目:athena    文件:GroupModBuilder.java   
private GroupModBuilder(GroupBuckets buckets, GroupId groupId,
                         GroupDescription.Type type, OFFactory factory,
                         Optional<Long> xid, Optional<DriverService> driverService) {
    this.buckets = buckets;
    this.groupId = groupId;
    this.type = type;
    this.factory = factory;
    this.xid = xid.orElse((long) 0);
    this.driverService = driverService;
}
项目:fresco_floodlight    文件:SwitchSyncRepresentation.java   
public OFPortDesc toOFPortDesc(OFFactory factory) {
    OFPortDesc.Builder builder = factory.buildPortDesc();
    builder.setPortNo(port.getPortNo());
    builder.setHwAddr(port.getHwAddr());
    builder.setName(port.getName());
    builder.setConfig(port.getConfig());
    builder.setState(port.getState());
    builder.setCurr(port.getCurr());
    builder.setAdvertised(port.getAdvertised());
    builder.setSupported(port.getSupported());
    builder.setPeer(port.getPeer());
    return builder.build();
}
项目:fresco_floodlight    文件:SwitchSyncRepresentation.java   
private static List<OFPortDesc> toOFPortDescList(OFFactory factory, Collection<SyncedPort> ports) {
    List<OFPortDesc> rv = new ArrayList<OFPortDesc>(ports.size());
    for (SyncedPort p: ports) {
        rv.add(p.toOFPortDesc(factory));
    }
    return rv;

}
项目:fresco_floodlight    文件:OFSwitch.java   
public OFSwitch(IOFConnectionBackend connection, @Nonnull OFFactory factory, @Nonnull IOFSwitchManager switchManager, 
        @Nonnull DatapathId datapathId) {
    if(connection == null)
        throw new NullPointerException("connection must not be null");
    if(!connection.getAuxId().equals(OFAuxId.MAIN))
        throw new IllegalArgumentException("connection must be the main connection");
    if(factory == null)
        throw new NullPointerException("factory must not be null");
    if(switchManager == null)
        throw new NullPointerException("switchManager must not be null");

    this.connected = true;
    this.factory = factory;
    this.switchManager = switchManager;
    this.datapathId = datapathId;
    this.attributes = new ConcurrentHashMap<Object, Object>();
    this.role = null;
    this.description = new SwitchDescription();
    this.portManager = new PortManager();
    this.status = SwitchStatus.HANDSHAKE;

    // Connections
    this.connections = new ConcurrentHashMap<OFAuxId, IOFConnectionBackend>();
    this.connections.put(connection.getAuxId(), connection);

    // Switch's controller connection
    this.controllerConnections = ImmutableMap.of();

    // Defaults properties for an ideal switch
    this.setAttribute(PROP_FASTWILDCARDS, EnumSet.allOf(OFFlowWildcards.class));
    this.setAttribute(PROP_SUPPORTS_OFPP_FLOOD, Boolean.TRUE);
    this.setAttribute(PROP_SUPPORTS_OFPP_TABLE, Boolean.TRUE);

    this.tableFeaturesByTableId = new HashMap<TableId, TableFeatures>();
    this.tables = new ArrayList<TableId>();

    this.securityKernel = switchManager.getSecurityKernelService();

}
项目:fresco_floodlight    文件:OFSwitchManager.java   
@Override
public IOFSwitchBackend getOFSwitchInstance(IOFConnectionBackend connection,
        SwitchDescription description,
        OFFactory factory, DatapathId datapathId) {

    return this.driverRegistry.getOFSwitchInstance(connection, description, factory, datapathId);
}
项目:fresco_floodlight    文件:OFSwitchBaseTest.java   
@Test
public void testMasterSlaveWrites() {
    OFFactory factory = OFFactories.getFactory(OFVersion.OF_13);
    OFFlowAdd fa = factory.buildFlowAdd().build();
    OFFlowStatsRequest fsr = factory.buildFlowStatsRequest().build();
    List<OFMessage> msgList = new ArrayList<OFMessage>();
    msgList.add(fa);
    msgList.add(fsr);

    reset(switchManager);
       expect(switchManager.isCategoryRegistered(LogicalOFMessageCategory.MAIN)).andReturn(true).times(6);
       switchManager.handleOutgoingMessage(sw, fa);
       expectLastCall().times(2);
       switchManager.handleOutgoingMessage(sw, fsr);
       expectLastCall().times(4);
       replay(switchManager);

    /* test master -- both messages should be written */
    sw.setControllerRole(OFControllerRole.ROLE_MASTER);
    assertTrue(sw.write(fa));
    assertTrue(sw.write(fsr));
    assertEquals(Collections.<OFMessage>emptyList(), sw.write(msgList));

    /* test slave -- flow-add (mod op) should fail each time; flow stats (read op) should pass */
    sw.setControllerRole(OFControllerRole.ROLE_SLAVE);
    assertFalse(sw.write(fa)); /* flow-add should be stopped (mod op) */
    assertTrue(sw.write(fsr)); /* stats request makes it (read op) */
    assertEquals(Collections.<OFMessage>singletonList(fa), sw.write(msgList)); /* return bad flow-add */
}
项目:fresco_floodlight    文件:OFSwitchHandshakeHandlerVer13Test.java   
public void handleDescStatsAndCreateSwitch() throws Exception {
    // build the stats reply
    OFDescStatsReply sr = createDescriptionStatsReply();

    reset(sw);
    SwitchDescription switchDescription = new SwitchDescription(sr);
    setupSwitchForInstantiationWithReset();
    sw.setPortDescStats(anyObject(OFPortDescStatsReply.class));
    expectLastCall().once();

    expect(sw.getOFFactory()).andReturn(factory).once();
    replay(sw);

    reset(switchManager);
    expect(switchManager.getHandshakePlugins()).andReturn(plugins).anyTimes();
    expect(
           switchManager.getOFSwitchInstance(anyObject(OFConnection.class),
                                          eq(switchDescription),
                                          anyObject(OFFactory.class),
                                          anyObject(DatapathId.class))).andReturn(sw).once();
    expect(switchManager.getNumRequiredConnections()).andReturn(1).anyTimes(); 
    switchManager.switchAdded(sw);
    expectLastCall().once();
    replay(switchManager);

    // send the description stats reply
    switchHandler.processOFMessage(sr);

    OFMessage msg = connection.retrieveMessage();
    assertThat(msg, CoreMatchers.instanceOf(OFTableFeaturesStatsRequest.class));
    verifyUniqueXids(msg);

    verify(sw, switchManager);
}
项目:fresco_floodlight    文件:OFSwitchHandshakeHandlerVer10Test.java   
public void handleDescStatsAndCreateSwitch(boolean switchDriverComplete) throws Exception {
    // build the stats reply
    OFDescStatsReply sr = createDescriptionStatsReply();

    reset(sw);
    SwitchDescription switchDescription = new SwitchDescription(sr);
    setupSwitchForInstantiationWithReset();
    sw.startDriverHandshake();
    expectLastCall().once();
    expect(sw.getOFFactory()).andReturn(factory).once();
    sw.isDriverHandshakeComplete();
    expectLastCall().andReturn(switchDriverComplete).once();

    if(factory.getVersion().compareTo(OFVersion.OF_13) >= 0) {
        sw.setPortDescStats(anyObject(OFPortDescStatsReply.class));
        expectLastCall().once();
    }

    replay(sw);

    reset(switchManager);
    expect(switchManager.getHandshakePlugins()).andReturn(plugins).anyTimes();
    expect(
           switchManager.getOFSwitchInstance(anyObject(OFConnection.class),
                                          eq(switchDescription),
                                          anyObject(OFFactory.class),
                                          anyObject(DatapathId.class))).andReturn(sw).once();
    switchManager.switchAdded(sw);
    expectLastCall().once();
    replay(switchManager);

    // send the description stats reply
    switchHandler.processOFMessage(sr);
}