本文整理汇总了Java中org.projectfloodlight.openflow.types.OFPort类的典型用法代码示例。如果您正苦于以下问题:Java OFPort类的具体用法?Java OFPort怎么用?Java OFPort使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OFPort类属于org.projectfloodlight.openflow.types包,在下文中一共展示了OFPort类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateSwitchPortStatusUpdate
import org.projectfloodlight.openflow.types.OFPort; //导入依赖的package包/类
private void generateSwitchPortStatusUpdate(DatapathId sw, OFPort port) {
UpdateOperation operation;
IOFSwitch iofSwitch = switchService.getSwitch(sw);
if (iofSwitch == null) return;
OFPortDesc ofp = iofSwitch.getPort(port);
if (ofp == null) return;
Set<OFPortState> srcPortState = ofp.getState();
boolean portUp = !srcPortState.contains(OFPortState.STP_BLOCK);
if (portUp) {
operation = UpdateOperation.PORT_UP;
} else {
operation = UpdateOperation.PORT_DOWN;
}
updates.add(new LDUpdate(sw, port, operation));
}
示例2: getPorts
import org.projectfloodlight.openflow.types.OFPort; //导入依赖的package包/类
/**
* Switch methods
*/
@Override
public Set<OFPort> getPorts(DatapathId sw) {
IOFSwitch iofSwitch = switchService.getSwitch(sw);
if (iofSwitch == null) return Collections.emptySet();
Collection<OFPort> ofpList = iofSwitch.getEnabledPortNumbers();
if (ofpList == null) return Collections.emptySet();
Set<OFPort> ports = new HashSet<OFPort>(ofpList);
Set<OFPort> qPorts = linkDiscoveryService.getQuarantinedPorts(sw);
if (qPorts != null)
ports.removeAll(qPorts);
return ports;
}
示例3: createTopologyFromLinks
import org.projectfloodlight.openflow.types.OFPort; //导入依赖的package包/类
public void createTopologyFromLinks(int [][] linkArray) throws Exception {
ILinkDiscovery.LinkType type = ILinkDiscovery.LinkType.DIRECT_LINK;
// Use topologymanager to write this test, it will make it a lot easier.
for (int i = 0; i < linkArray.length; i++) {
int [] r = linkArray[i];
if (r[4] == DIRECT_LINK)
type= ILinkDiscovery.LinkType.DIRECT_LINK;
else if (r[4] == MULTIHOP_LINK)
type= ILinkDiscovery.LinkType.MULTIHOP_LINK;
else if (r[4] == TUNNEL_LINK)
type = ILinkDiscovery.LinkType.TUNNEL;
topologyManager.addOrUpdateLink(DatapathId.of(r[0]), OFPort.of(r[1]), DatapathId.of(r[2]), OFPort.of(r[3]), type);
}
topologyManager.createNewInstance();
}
示例4: oneSwitchPopFlowMod
import org.projectfloodlight.openflow.types.OFPort; //导入依赖的package包/类
default OFFlowAdd oneSwitchPopFlowMod(int inputPort, int outputPort, int inputVlan, long meterId, long cookie) {
return ofFactory.buildFlowAdd()
.setCookie(U64.of(cookie & FLOW_COOKIE_MASK))
.setHardTimeout(FlowModUtils.INFINITE_TIMEOUT)
.setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT)
.setBufferId(OFBufferId.NO_BUFFER)
.setPriority(FlowModUtils.PRIORITY_VERY_HIGH)
.setMatch(ofFactory.buildMatch()
.setExact(MatchField.IN_PORT, OFPort.of(inputPort))
.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(inputVlan))
.build())
.setInstructions(Arrays.asList(
ofFactory.instructions().buildMeter().setMeterId(meterId).build(),
ofFactory.instructions().applyActions(Arrays.asList(
ofFactory.actions().popVlan(),
ofFactory.actions().buildOutput()
.setMaxLen(0xFFFFFFFF)
.setPort(OFPort.of(outputPort))
.build()))
.createBuilder()
.build()))
.setXid(0L)
.build();
}
示例5: sendArpReply
import org.projectfloodlight.openflow.types.OFPort; //导入依赖的package包/类
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);
}
示例6: egressPopFlowMod
import org.projectfloodlight.openflow.types.OFPort; //导入依赖的package包/类
@Override
public OFFlowAdd egressPopFlowMod(int inputPort, int outputPort, int transitVlan, long cookie) {
return ofFactory.buildFlowAdd()
.setCookie(U64.of(cookie & FLOW_COOKIE_MASK))
.setHardTimeout(FlowModUtils.INFINITE_TIMEOUT)
.setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT)
.setBufferId(OFBufferId.NO_BUFFER)
.setPriority(FlowModUtils.PRIORITY_VERY_HIGH)
.setMatch(ofFactory.buildMatch()
.setExact(MatchField.IN_PORT, OFPort.of(inputPort))
.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(transitVlan))
.build())
.setInstructions(singletonList(
ofFactory.instructions().applyActions(Arrays.asList(
ofFactory.actions().popVlan(),
ofFactory.actions().popVlan(),
ofFactory.actions().buildOutput()
.setMaxLen(0xFFFFFFFF)
.setPort(OFPort.of(outputPort))
.build()))
.createBuilder()
.build()))
.setXid(0L)
.build();
}
示例7: getSourceEntityFromPacket
import org.projectfloodlight.openflow.types.OFPort; //导入依赖的package包/类
/**
* 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 nwSrc = getSrcNwAddr(eth, dlAddr);
return new Entity(dlAddr,
vlan,
nwSrc,
swdpid,
port,
new Date());
}
示例8: testAddOrUpdateLinkToSelf
import org.projectfloodlight.openflow.types.OFPort; //导入依赖的package包/类
@Test
public void testAddOrUpdateLinkToSelf() throws Exception {
LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager();
Link lt = new Link(DatapathId.of(1L), OFPort.of(2), DatapathId.of(2L), 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);
// check invariants hold
assertNotNull(linkDiscovery.switchLinks.get(lt.getSrc()));
assertTrue(linkDiscovery.switchLinks.get(lt.getSrc()).contains(lt));
assertNotNull(linkDiscovery.portLinks.get(srcNpt));
assertTrue(linkDiscovery.portLinks.get(srcNpt).contains(lt));
assertNotNull(linkDiscovery.portLinks.get(dstNpt));
assertTrue(linkDiscovery.portLinks.get(dstNpt).contains(lt));
assertTrue(linkDiscovery.links.containsKey(lt));
}
示例9: createMatchFromPacket
import org.projectfloodlight.openflow.types.OFPort; //导入依赖的package包/类
protected Match createMatchFromPacket(IOFSwitch sw, OFPort inPort, FloodlightContext cntx) {
// The packet in match will only contain the port number.
// We need to add in specifics for the hosts we're routing between.
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
MacAddress srcMac = eth.getSourceMACAddress();
MacAddress dstMac = eth.getDestinationMACAddress();
Match.Builder mb = sw.getOFFactory().buildMatch();
mb.setExact(MatchField.IN_PORT, inPort)
.setExact(MatchField.ETH_SRC, srcMac)
.setExact(MatchField.ETH_DST, dstMac);
if (!vlan.equals(VlanVid.ZERO)) {
mb.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlanVid(vlan));
}
return mb.build();
}
示例10: testUncastPacket
import org.projectfloodlight.openflow.types.OFPort; //导入依赖的package包/类
@Test
public void testUncastPacket() {
// Generate the VerificationPacket
OFPacketOut packet = pvs.generateVerificationPacket(sw1, OFPort.of(1), sw2);
// Source MAC will always be that of sw1 for both Unicast and Broadcast
byte[] srcMacActual = Arrays.copyOfRange(packet.getData(), 6, 12);
assertArrayEquals(MacAddress.of(sw1HwAddrTarget).getBytes(), srcMacActual);
// Destination MAC should be that of sw2 for Unicast Packet
byte[] dstMacActual = Arrays.copyOfRange(packet.getData(), 0, 6);
assertArrayEquals(MacAddress.of(sw2HwAddrTarget).getBytes(), dstMacActual);
// Source and Destination IP's are the respective switch IP's
byte[] srcIpActual = Arrays.copyOfRange(packet.getData(), 26, 30);
assertArrayEquals(srcIpTarget.getAddress().getAddress(), srcIpActual);
byte[] dstIpActual = Arrays.copyOfRange(packet.getData(), 30, 34);
assertArrayEquals(dstIpTarget.getAddress().getAddress(), dstIpActual);
}
示例11: DhcpDiscoveryRequestOFPacketIn
import org.projectfloodlight.openflow.types.OFPort; //导入依赖的package包/类
/**
* 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();
}
示例12: processNewPort
import org.projectfloodlight.openflow.types.OFPort; //导入依赖的package包/类
/**
* Process a new port. If link discovery is disabled on the port, then do
* nothing. If autoportfast feature is enabled and the port is a fast port,
* then do nothing. Otherwise, send LLDP message. Add the port to
* quarantine.
*
* @param sw
* @param p
*/
private void processNewPort(DatapathId sw, OFPort p) {
if (isLinkDiscoverySuppressed(sw, p)) {
// Do nothing as link discovery is suppressed.
return;
}
IOFSwitch iofSwitch = switchService.getSwitch(sw);
if (iofSwitch == null) {
return;
}
NodePortTuple npt = new NodePortTuple(sw, p);
discover(sw, p);
addToQuarantineQueue(npt);
}
示例13: removeSwitch
import org.projectfloodlight.openflow.types.OFPort; //导入依赖的package包/类
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);
}
}
示例14: sendPacket
import org.projectfloodlight.openflow.types.OFPort; //导入依赖的package包/类
private void sendPacket(Ethernet eth) {
List<Instruction> ins = treatmentBuilder().build().allInstructions();
OFPort p = null;
//TODO: support arbitrary list of treatments must be supported in ofPacketContext
for (Instruction i : ins) {
if (i.type() == Type.OUTPUT) {
p = buildPort(((OutputInstruction) i).port());
break; //for now...
}
}
if (eth == null) {
ofPktCtx.build(p);
} else {
ofPktCtx.build(eth, p);
}
ofPktCtx.send();
}
示例15: testSingleMessageWrite
import org.projectfloodlight.openflow.types.OFPort; //导入依赖的package包/类
/** write a packetOut, which is buffered */
@Test(timeout = 5000)
public void testSingleMessageWrite() throws InterruptedException, ExecutionException {
Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();
OFPacketOut packetOut = factory.buildPacketOut()
.setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
.setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
.build();
conn.write(packetOut);
assertThat("Write should have been flushed", cMsgList.hasCaptured(), equalTo(true));
List<OFMessage> value = cMsgList.getValue();
logger.info("Captured channel write: "+value);
assertThat("Should have captured MsgList", cMsgList.getValue(),
Matchers.<OFMessage> contains(packetOut));
}