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)); }
/** * 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; }
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(); }
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(); }
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); }
@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(); }
/** * 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()); }
@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)); }
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(); }
@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); }
/** * 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(); }
/** * 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); }
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); } }
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(); }
/** 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)); }
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; }
@Test public void testDeleteLink() throws Exception { LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); Link lt = new Link(DatapathId.of(1L), OFPort.of(2), DatapathId.of(2L), OFPort.of(1)); LinkInfo info = new LinkInfo(new Date(), new Date(), null); linkDiscovery.addOrUpdateLink(lt, info); linkDiscovery.deleteLinks(Collections.singletonList(lt), "Test"); // check invariants hold assertNull(linkDiscovery.switchLinks.get(lt.getSrc())); assertNull(linkDiscovery.switchLinks.get(lt.getDst())); assertNull(linkDiscovery.portLinks.get(lt.getSrc())); assertNull(linkDiscovery.portLinks.get(lt.getDst())); assertTrue(linkDiscovery.links.isEmpty()); }
private OFMessage createHubPacketOut(IOFSwitch sw, OFMessage msg) { OFPacketIn pi = (OFPacketIn) msg; OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut(); pob.setBufferId(pi.getBufferId()).setXid(pi.getXid()).setInPort((pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT))); // set actions OFActionOutput.Builder actionBuilder = sw.getOFFactory().actions().buildOutput(); actionBuilder.setPort(OFPort.FLOOD); pob.setActions(Collections.singletonList((OFAction) actionBuilder.build())); // set data if it is included in the packetin if (pi.getBufferId() == OFBufferId.NO_BUFFER) { byte[] packetData = pi.getData(); pob.setData(packetData); } return pob.build(); }
/** write a list of messages */ @Test(timeout = 5000) public void testMessageWriteList() throws InterruptedException, ExecutionException { Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList(); OFHello hello = factory.hello(ImmutableList.<OFHelloElem>of()); 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(ImmutableList.of(hello, packetOut)); eventLoop.runTasks(); assertThat("Write should have been written", 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(hello, packetOut)); }
/** * If the packet-in switch port is disabled for all data traffic, then * the packet will be dropped. Otherwise, the packet will follow the * normal processing chain. * @param sw * @param pi * @param cntx * @return */ protected Command dropFilter(DatapathId sw, OFPacketIn pi, FloodlightContext cntx) { Command result = Command.CONTINUE; OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)); // If the input port is not allowed for data traffic, drop everything. // BDDP packets will not reach this stage. if (isAllowed(sw, inPort) == false) { if (log.isTraceEnabled()) { log.trace("Ignoring packet because of topology " + "restriction on switch={}, port={}", sw.getLong(), inPort.getPortNumber()); result = Command.STOP; } } return result; }
/** * Creates a OFPacketOut with the OFPacketIn data that is flooded on all ports unless * the port is blocked, in which case the packet will be dropped. * @param sw The switch that receives the OFPacketIn * @param pi The OFPacketIn that came to the switch * @param cntx The FloodlightContext associated with this OFPacketIn */ protected void doFlood(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) { OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)); // Set Action to flood OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut(); List<OFAction> actions = new ArrayList<OFAction>(); Set<OFPort> broadcastPorts = this.topologyService.getSwitchBroadcastPorts(sw.getId()); if (broadcastPorts == null) { log.debug("BroadcastPorts returned null. Assuming single switch w/no links."); /* Must be a single-switch w/no links */ broadcastPorts = Collections.singleton(OFPort.FLOOD); } for (OFPort p : broadcastPorts) { if (p.equals(inPort)) continue; actions.add(sw.getOFFactory().actions().output(p, Integer.MAX_VALUE)); } pob.setActions(actions); // log.info("actions {}",actions); // set buffer-id, in-port and packet-data based on packet-in pob.setBufferId(OFBufferId.NO_BUFFER); pob.setInPort(inPort); pob.setData(pi.getData()); try { if (log.isTraceEnabled()) { log.trace("Writing flood PacketOut switch={} packet-in={} packet-out={}", new Object[] {sw, pi, pob.build()}); } messageDamper.write(sw, pob.build()); } catch (IOException e) { log.error("Failure writing PacketOut switch={} packet-in={} packet-out={}", new Object[] {sw, pi, pob.build()}, e); } return; }
@Override public NodePortTuple getAllowedIncomingBroadcastPort(DatapathId src, OFPort srcPort, boolean tunnelEnabled) { TopologyInstance ti = getCurrentInstance(tunnelEnabled); return ti.getAllowedIncomingBroadcastPort(src,srcPort); }
/** * 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."); }
/** * Adds a host to the MAC/VLAN->SwitchPort mapping * @param sw The switch to add the mapping to * @param mac The MAC address of the host to add * @param vlan The VLAN that the host is on * @param portVal The switchport that the host is on */ protected void addToPortMap(IOFSwitch sw, MacAddress mac, VlanVid vlan, OFPort portVal) { Map<MacVlanPair, OFPort> swMap = macVlanToSwitchPortMap.get(sw); if (vlan == VlanVid.FULL_MASK || vlan == null) { vlan = VlanVid.ofVlan(0); } if (swMap == null) { // May be accessed by REST API so we need to make it thread safe swMap = Collections.synchronizedMap(new LRULinkedHashMap<MacVlanPair, OFPort>(MAX_MACS_PER_SWITCH)); macVlanToSwitchPortMap.put(sw, swMap); } swMap.put(new MacVlanPair(mac, vlan), portVal); }
@Override public boolean sendDiscoveryMessage(DatapathId srcSwId, OFPort port) { IOFSwitch srcSwitch = switchService.getSwitch(srcSwId); if (srcSwitch == null) { return false; } OFPacketOut ofPacketOut = (generateVerificationPacket(srcSwitch, port)); logger.debug("sending verification packet out {}/{}: {}", srcSwitch.getId().toString(), port.getPortNumber(), Hex.encodeHexString(ofPacketOut.getData())); return srcSwitch.write(ofPacketOut); }
OFPortDescStatsReply getPortDescStatsReply() { OFPortDesc portDesc = factory.buildPortDesc() .setName("Eth1") .setPortNo(OFPort.of(1)) .build(); return factory.buildPortDescStatsReply() .setEntries(ImmutableList.<OFPortDesc>of(portDesc)) .build(); }
/** * @param sw * the switch object that we wish to get flows from * @param outPort * the output action port we wish to find flows with * @return a list of OFFlowStatisticsReply objects or essentially flows */ public List<OFFlowStatsReply> getFlows(IOFSwitch sw, OFPort outPort) { statsReply = new ArrayList<OFFlowStatsReply>(); List<OFFlowStatsReply> values = null; Future<List<OFFlowStatsReply>> future; // Statistics request object for getting flows OFFlowStatsRequest req = sw.getOFFactory().buildFlowStatsRequest() .setMatch(sw.getOFFactory().buildMatch().build()) .setOutPort(outPort) .setTableId(TableId.ALL) .build(); try { // System.out.println(sw.getStatistics(req)); future = sw.writeStatsRequest(req); values = future.get(10, TimeUnit.SECONDS); if (values != null) { for (OFFlowStatsReply stat : values) { statsReply.add(stat); } } } catch (Exception e) { log.error("Failure retrieving statistics from switch " + sw, e); } return statsReply; }
private SwitchPortBandwidth(DatapathId d, OFPort p, U64 rx, U64 tx, U64 rxValue, U64 txValue) { id = d; pt = p; this.rx = rx; this.tx = tx; time = new Date(); this.rxValue = rxValue; this.txValue = txValue; }
@Override public OFFlowAdd egressPushFlowMod(int inputPort, int outputPort, int transitVlan, int outputVlan, 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().buildSetField() .setField(ofFactory.oxms().buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(outputVlan)) .build()) .build(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Get("json") public List<NodePortTuple> retrieve() { IRoutingService routing = (IRoutingService)getContext().getAttributes(). get(IRoutingService.class.getCanonicalName()); String srcDpid = (String) getRequestAttributes().get("src-dpid"); String srcPort = (String) getRequestAttributes().get("src-port"); String dstDpid = (String) getRequestAttributes().get("dst-dpid"); String dstPort = (String) getRequestAttributes().get("dst-port"); log.debug( srcDpid + "--" + srcPort + "--" + dstDpid + "--" + dstPort); DatapathId longSrcDpid = DatapathId.of(srcDpid); OFPort shortSrcPort = OFPort.of(Integer.parseInt(srcPort)); DatapathId longDstDpid = DatapathId.of(dstDpid); OFPort shortDstPort = OFPort.of(Integer.parseInt(dstPort)); Route result = routing.getRoute(longSrcDpid, shortSrcPort, longDstDpid, shortDstPort, U64.of(0)); if (result != null) { return routing.getRoute(longSrcDpid, shortSrcPort, longDstDpid, shortDstPort, U64.of(0)).getPath(); } else { log.debug("ERROR! no route found"); return null; } }
@Override OFFeaturesReply getFeaturesReply() { OFPortDesc portDesc = factory.buildPortDesc() .setName("Eth1") .setPortNo(OFPort.of(1)) .build(); return factory.buildFeaturesReply() .setDatapathId(dpid) .setNBuffers(1) .setNTables((short)1) .setCapabilities(EnumSet.<OFCapabilities>of(OFCapabilities.FLOW_STATS, OFCapabilities.TABLE_STATS)) .setActions(EnumSet.<OFActionType>of(OFActionType.SET_VLAN_PCP)) .setPorts(ImmutableList.<OFPortDesc>of(portDesc)) .build(); }
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; }
/** * Get the set of ports to eliminate for sending out BDDP. The method * returns all the ports that are suppressed for link discovery on the * switch. * packets. * @param sid * @return */ protected Set<OFPort> getPortsToEliminateForBDDP(DatapathId sid) { Set<NodePortTuple> suppressedNptList = linkDiscoveryService.getSuppressLLDPsInfo(); if (suppressedNptList == null) return null; Set<OFPort> resultPorts = new HashSet<OFPort>(); for(NodePortTuple npt: suppressedNptList) { if (npt.getNodeId() == sid) { resultPorts.add(npt.getPortId()); } } return resultPorts; }
private void sendQueueStatistic() { if (sw.getRole() != RoleState.MASTER) { return; } //Long statsXid = xidAtomic.getAndIncrement(); OFQueueStatsRequest queueRequest = sw.factory().buildQueueStatsRequest() .setPortNo(OFPort.ANY) .setQueueId(0xffffffff) .setXid(1129) .build(); sw.sendMsg(queueRequest); }
@Before public void setUp() throws Exception { super.setUp(); mockFloodlightProvider = getMockFloodlightProvider(); hub = new Hub(); mockFloodlightProvider.addOFMessageListener(OFType.PACKET_IN, hub); hub.setFloodlightProvider(mockFloodlightProvider); // Build our test packet this.testPacket = new Ethernet() .setDestinationMACAddress("00:11:22:33:44:55") .setSourceMACAddress("00:44:33:22:11:00") .setEtherType(EthType.IPv4) .setPayload( new IPv4() .setTtl((byte) 128) .setSourceAddress("192.168.1.1") .setDestinationAddress("192.168.1.2") .setPayload(new UDP() .setSourcePort((short) 5000) .setDestinationPort((short) 5001) .setPayload(new Data(new byte[] {0x01})))); this.testPacketSerialized = testPacket.serialize(); // Build the PacketIn this.packetIn = (OFPacketIn) OFFactories.getFactory(OFVersion.OF_13).buildPacketIn() .setBufferId(OFBufferId.NO_BUFFER) .setMatch(OFFactories.getFactory(OFVersion.OF_13).buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(1)) .build()) .setData(this.testPacketSerialized) .setReason(OFPacketInReason.NO_MATCH) .setTotalLen((short) this.testPacketSerialized.length).build(); }
@Override public void run() { if (sw.getRole() == RoleState.MASTER) { log.trace("Collecting stats for {}", sw.getStringId()); OFFlowStatsRequest request = sw.factory().buildFlowStatsRequest() .setMatch(sw.factory().matchWildcardAll()) .setTableId(TableId.ALL) .setOutPort(OFPort.NO_MASK) .build(); sw.sendMsg(request); } }
/** * Builds the GroupAdd OF message. * * @return GroupAdd OF message */ public OFGroupAdd buildGroupAdd() { List<OFBucket> ofBuckets = new ArrayList<OFBucket>(); for (GroupBucket bucket: buckets.buckets()) { List<OFAction> actions = buildActions(bucket.treatment()); OFBucket.Builder bucketBuilder = factory.buildBucket(); bucketBuilder.setActions(actions); if (type == GroupDescription.Type.SELECT) { bucketBuilder.setWeight(1); } if (type == GroupDescription.Type.FAILOVER && bucket.watchPort() != null) { bucketBuilder.setWatchPort(OFPort.of((int) bucket.watchPort().toLong())); } else { bucketBuilder.setWatchPort(OFPort.ANY); } if (type == GroupDescription.Type.FAILOVER && bucket.watchGroup() != null) { bucketBuilder.setWatchGroup(OFGroup.of(bucket.watchGroup().id())); } else { bucketBuilder.setWatchGroup(OFGroup.ANY); } OFBucket ofBucket = bucketBuilder.build(); ofBuckets.add(ofBucket); } OFGroupAdd groupMsg = factory.buildGroupAdd() .setGroup(OFGroup.of(groupId.id())) .setBuckets(ofBuckets) .setGroupType(getOFGroupType(type)) .setXid(xid) .build(); return groupMsg; }
/** * Checks if the new attachment point port is consistent with the * old attachment point port. */ @Override public boolean isConsistent(DatapathId oldSw, OFPort oldPort, DatapathId newSw, OFPort newPort) { return isConsistent(oldSw, oldPort, newSw, newPort, true); }