Java 类org.projectfloodlight.openflow.types.U64 实例源码
项目:fresco_floodlight
文件:LinkDiscoveryManagerTest.java
@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), U64.ZERO);
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());
}
项目:open-kilda
文件:OutputCommands.java
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();
}
项目:fresco_floodlight
文件:LinkDiscoveryManagerTest.java
@Test
public void testRemovedSwitchSelf() {
LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager();
IOFSwitch sw1 = createMockSwitch(1L);
replay(sw1);
Link lt = new Link(DatapathId.of(1L), OFPort.of(2), DatapathId.of(1L), OFPort.of(3), U64.ZERO);
LinkInfo info = new LinkInfo(new Date(),
new Date(), null);
linkDiscovery.addOrUpdateLink(lt, info);
// Mock up our expected behavior
linkDiscovery.switchRemoved(sw1.getId());
verify(sw1);
// check invariants hold
assertNull(linkDiscovery.switchLinks.get(lt.getSrc()));
assertNull(linkDiscovery.portLinks.get(lt.getSrc()));
assertNull(linkDiscovery.portLinks.get(lt.getDst()));
assertTrue(linkDiscovery.links.isEmpty());
}
项目:athena
文件:FlowModBuilderVer10.java
@Override
public OFFlowAdd buildFlowAdd() {
Match match = buildMatch();
List<OFAction> actions = buildActions();
long cookie = flowRule().id().value();
OFFlowAdd fm = factory().buildFlowAdd()
.setXid(xid)
.setCookie(U64.of(cookie))
.setBufferId(OFBufferId.NO_BUFFER)
.setActions(actions)
.setMatch(match)
.setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
.setPriority(flowRule().priority())
.build();
return fm;
}
项目:athena
文件:FlowModBuilderVer10.java
@Override
public OFFlowDelete buildFlowDel() {
Match match = buildMatch();
long cookie = flowRule().id().value();
OFFlowDelete fm = factory().buildFlowDelete()
.setXid(xid)
.setCookie(U64.of(cookie))
.setBufferId(OFBufferId.NO_BUFFER)
.setMatch(match)
.setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
.setPriority(flowRule().priority())
.build();
return fm;
}
项目:fresco_floodlight
文件:FP_FloodlightRTE.java
private OFFlowMod createFRESCOFlowMod(IOFSwitch sw, Match match, List<OFAction> actions, int priority){
OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowAdd();;
fmb.setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT);
fmb.setHardTimeout(FlowModUtils.INFINITE_TIMEOUT);
fmb.setBufferId(OFBufferId.NO_BUFFER);
fmb.setOutPort(OFPort.ANY);
fmb.setCookie(U64.of(0));
fmb.setPriority(U16.t(priority));
fmb.setMatch(match);
fmb.setActions(actions);
return fmb.build();
}
项目:fresco_floodlight
文件:LinkDiscoveryManagerTest.java
@Test
public void testRemovedSwitch() {
LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager();
Link lt = new Link(DatapathId.of(1L), OFPort.of(2), DatapathId.of(2L), OFPort.of(1), U64.ZERO);
NodePortTuple srcNpt = new NodePortTuple(DatapathId.of(1L), OFPort.of(2));
NodePortTuple dstNpt = new NodePortTuple(DatapathId.of(2L), OFPort.of(1));
LinkInfo info = new LinkInfo(new Date(),
new Date(), null);
linkDiscovery.addOrUpdateLink(lt, info);
IOFSwitch sw1 = getMockSwitchService().getSwitch(DatapathId.of(1L));
IOFSwitch sw2 = getMockSwitchService().getSwitch(DatapathId.of(2L));
// Mock up our expected behavior
linkDiscovery.switchRemoved(sw1.getId());
verify(sw1, sw2);
// 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
文件:TopologyInstance.java
protected Route getRoute(DatapathId srcId, DatapathId dstId, U64 cookie) {
// Return null route if srcId equals dstId
if (srcId.equals(dstId)) return null;
RouteId id = new RouteId(srcId, dstId);
Route result = null;
try {
result = pathcache.get(id);
} catch (Exception e) {
log.error("{}", e);
}
if (log.isTraceEnabled()) {
log.trace("getRoute: {} -> {}", id, result);
}
return result;
}
项目:fresco_floodlight
文件:LinkInfo.java
/**
* Retrieve the current latency, and if necessary
* compute and replace the current latency with an
* updated latency based on the historical average.
* @return the most up-to-date latency as permitted by algorithm
*/
private U64 getLatency() {
U64 newLatency = getLatencyHistoryAverage();
if (newLatency != null) {
/* check threshold */
if ((((double) Math.abs(newLatency.getValue() - currentLatency.getValue()))
/ (currentLatency.getValue() == 0 ? 1 : currentLatency.getValue())
)
>= latencyUpdateThreshold) {
/* perform update */
log.debug("Updating link latency from {} to {}", currentLatency.getValue(), newLatency.getValue());
currentLatency = newLatency;
}
}
return currentLatency;
}
项目:fresco_floodlight
文件:TopologyManager.java
public void addOrUpdateLink(DatapathId srcId, OFPort srcPort, DatapathId dstId,
OFPort dstPort, U64 latency, LinkType type) {
Link link = new Link(srcId, srcPort, dstId, dstPort, latency);
if (type.equals(LinkType.MULTIHOP_LINK)) {
addPortToSwitch(srcId, srcPort);
addPortToSwitch(dstId, dstPort);
addLinkToStructure(switchPortLinks, link);
addLinkToStructure(portBroadcastDomainLinks, link);
dtLinksUpdated = removeLinkFromStructure(directLinks, link);
linksUpdated = true;
} else if (type.equals(LinkType.DIRECT_LINK)) {
addPortToSwitch(srcId, srcPort);
addPortToSwitch(dstId, dstPort);
addLinkToStructure(switchPortLinks, link);
addLinkToStructure(directLinks, link);
removeLinkFromStructure(portBroadcastDomainLinks, link);
dtLinksUpdated = true;
linksUpdated = true;
} else if (type.equals(LinkType.TUNNEL)) {
addOrUpdateTunnelLink(srcId, srcPort, dstId, dstPort, latency);
}
}
项目: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());
}
项目:fresco_floodlight
文件:OFSwitchHandlerTestBase.java
protected OFTableFeaturesStatsReply createTableFeaturesStatsReply() {
OFTableFeaturesStatsReply statsReply = factory.buildTableFeaturesStatsReply()
.setEntries(Collections.singletonList(factory.buildTableFeatures()
.setConfig(0)
.setMaxEntries(100)
.setMetadataMatch(U64.NO_MASK)
.setMetadataWrite(U64.NO_MASK)
.setName("MyTable")
.setTableId(TableId.of(1))
.setProperties(Collections.singletonList((OFTableFeatureProp)factory.buildTableFeaturePropMatch()
.setOxmIds(Collections.singletonList(U32.of(100)))
.build())
).build()
)
).build();
return statsReply;
}
项目: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;
}
项目: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
文件:OutputCommands.java
default OFFlowAdd oneSwitchReplaceFlowMod(int inputPort, int outputPort, int inputVlan, int outputVlan,
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().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();
}
项目:open-kilda
文件:OutputCommands.java
default OFFlowAdd oneSwitchPushFlowMod(int inputPort, int outputPort, int outputVlan, 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))
.build())
.setInstructions(Arrays.asList(
ofFactory.instructions().buildMeter().setMeterId(meterId).build(),
ofFactory.instructions().applyActions(Arrays.asList(
ofFactory.actions().buildPushVlan()
.setEthertype(EthType.of(ETH_TYPE))
.build(),
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();
}
项目:open-kilda
文件:ReplaceSchemeOutputCommands.java
@Override
public OFFlowAdd ingressMatchVlanIdFlowMod(int inputPort, int outputPort, int inputVlan, int transitVlan,
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().buildSetField()
.setField(ofFactory.oxms().buildVlanVid()
.setValue(OFVlanVidMatch.ofVlan(transitVlan))
.build())
.build(),
ofFactory.actions().buildOutput()
.setMaxLen(0xFFFFFFFF)
.setPort(OFPort.of(outputPort))
.build()))
.createBuilder()
.build()))
.setXid(0L)
.build();
}
项目:open-kilda
文件:ReplaceSchemeOutputCommands.java
@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();
}
项目:open-kilda
文件:PushSchemeOutputCommands.java
@Override
public OFFlowAdd ingressNoMatchVlanIdFlowMod(int inputPort, int outputPort, int transitVlan,
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))
.build())
.setInstructions(Arrays.asList(
ofFactory.instructions().buildMeter().setMeterId(meterId).build(),
ofFactory.instructions().applyActions(Arrays.asList(
ofFactory.actions().buildPushVlan()
.setEthertype(EthType.of(ETH_TYPE))
.build(),
ofFactory.actions().buildSetField()
.setField(ofFactory.oxms().buildVlanVid()
.setValue(OFVlanVidMatch.ofVlan(transitVlan))
.build())
.build(),
ofFactory.actions().buildOutput()
.setMaxLen(0xFFFFFFFF)
.setPort(OFPort.of(outputPort))
.build()))
.createBuilder()
.build()))
.setXid(0L)
.build();
}
项目:open-kilda
文件:PushSchemeOutputCommands.java
@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().popVlan(),
ofFactory.actions().buildPushVlan()
.setEthertype(EthType.of(ETH_TYPE))
.build(),
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();
}
项目:iTAP-controller
文件:AppCookie.java
/**
* Encapsulate an application ID and a user block of stuff into a cookie
*
* @param application An ID to identify the application
* @param user Some application specific data
* @return a cookie for use in OFFlowMod.setCookie()
* @throws IllegalStateException if the application has not been registered
*/
static public U64 makeCookie(int application, int user) {
if (!appIdMap.containsKey(application)) {
throw new AppIDNotRegisteredException(application);
}
long longApp = application;
long longUser = user & USER_MASK; // mask to prevent sign extend
return U64.of((longApp << APP_ID_SHIFT) | longUser);
}
项目:open-kilda
文件:PushSchemeOutputCommands.java
@Override
public OFFlowAdd egressReplaceFlowMod(int inputPort, int outputPort, int inputVlan, 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(inputVlan))
.build())
.setInstructions(singletonList(
ofFactory.instructions().applyActions(Arrays.asList(
ofFactory.actions().popVlan(),
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();
}
项目:athena
文件:RoleManager.java
private int sendOF13RoleRequest(RoleState role) throws IOException {
// Convert the role enum to the appropriate role to send
OFControllerRole roleToSend = OFControllerRole.ROLE_NOCHANGE;
switch (role) {
case EQUAL:
roleToSend = OFControllerRole.ROLE_EQUAL;
break;
case MASTER:
roleToSend = OFControllerRole.ROLE_MASTER;
break;
case SLAVE:
roleToSend = OFControllerRole.ROLE_SLAVE;
break;
default:
log.warn("Sending default role.noChange to switch {}."
+ " Should only be used for queries.", sw);
}
int xid = sw.getNextTransactionId();
OFRoleRequest rrm = OFFactories.getFactory(OFVersion.OF_13)
.buildRoleRequest()
.setRole(roleToSend)
.setXid(xid)
//FIXME fix below when we actually use generation ids
.setGenerationId(U64.ZERO)
.build();
sw.sendRoleRequest(rrm);
return xid;
}
项目:fresco_floodlight
文件:Forwarding.java
protected void doDropFlow(IOFSwitch sw, OFPacketIn pi, IRoutingDecision decision, FloodlightContext cntx) {
OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT));
Match m = createMatchFromPacket(sw, inPort, cntx);
OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowAdd(); // this will be a drop-flow; a flow that will not output to any ports
List<OFAction> actions = new ArrayList<OFAction>(); // set no action to drop
U64 cookie = AppCookie.makeCookie(FORWARDING_APP_ID, 0);
log.info("Droppingggg");
fmb.setCookie(cookie)
.setHardTimeout(FLOWMOD_DEFAULT_HARD_TIMEOUT)
.setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT)
.setBufferId(OFBufferId.NO_BUFFER)
.setMatch(m)
.setPriority(FLOWMOD_DEFAULT_PRIORITY);
FlowModUtils.setActions(fmb, actions, sw);
try {
if (log.isDebugEnabled()) {
log.debug("write drop flow-mod sw={} match={} flow-mod={}",
new Object[] { sw, m, fmb.build() });
}
boolean dampened = messageDamper.write(sw, fmb.build());
log.debug("OFMessage dampened: {}", dampened);
} catch (IOException e) {
log.error("Failure writing drop flow mod", e);
}
}
项目:iTAP-controller
文件:RouteResource.java
@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;
}
}
项目:fresco_floodlight
文件:VirtualNetworkFilter.java
/**
* Writes a FlowMod to a switch that inserts a drop flow.
* @param sw The switch to write the FlowMod to.
* @param pi The corresponding OFPacketIn. Used to create the OFMatch structure.
* @param cntx The FloodlightContext that gets passed to the switch.
*/
protected void doDropFlow(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
if (log.isTraceEnabled()) {
log.trace("doDropFlow pi={} srcSwitch={}",
new Object[] { pi, sw });
}
if (sw == null) {
log.warn("Switch is null, not installing drop flowmod for PacketIn {}", pi);
return;
}
// Create flow-mod based on packet-in and src-switch
OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowModify();
List<OFAction> actions = new ArrayList<OFAction>(); // no actions = drop
U64 cookie = AppCookie.makeCookie(APP_ID, 0);
fmb.setCookie(cookie)
.setIdleTimeout(ForwardingBase.FLOWMOD_DEFAULT_IDLE_TIMEOUT)
.setHardTimeout(ForwardingBase.FLOWMOD_DEFAULT_HARD_TIMEOUT)
.setBufferId(OFBufferId.NO_BUFFER)
.setMatch(pi.getMatch())
.setActions(actions);
if (log.isTraceEnabled()) {
log.trace("write drop flow-mod srcSwitch={} match={} " +
"pi={} flow-mod={}",
new Object[] {sw, pi.getMatch(), pi, fmb.build()});
}
sw.write(fmb.build());
return;
}
项目:fresco_floodlight
文件:LinkInfo.java
public LinkInfo(Date firstSeenTime, Date lastLldpReceivedTime, Date lastBddpReceivedTime) {
this.firstSeenTime = firstSeenTime;
this.lastLldpReceivedTime = lastLldpReceivedTime;
this.lastBddpReceivedTime = lastBddpReceivedTime;
this.currentLatency = null;
this.latencyHistory = new ArrayDeque<U64>(LinkDiscoveryManager.LATENCY_HISTORY_SIZE);
this.latencyHistoryWindow = LinkDiscoveryManager.LATENCY_HISTORY_SIZE;
this.latencyUpdateThreshold = LinkDiscoveryManager.LATENCY_UPDATE_THRESHOLD;
}
项目:fresco_floodlight
文件:LinkInfo.java
public LinkInfo(LinkInfo fromLinkInfo) {
this.firstSeenTime = fromLinkInfo.getFirstSeenTime();
this.lastLldpReceivedTime = fromLinkInfo.getUnicastValidTime();
this.lastBddpReceivedTime = fromLinkInfo.getMulticastValidTime();
this.currentLatency = fromLinkInfo.currentLatency;
this.latencyHistory = new ArrayDeque<U64>(fromLinkInfo.getLatencyHistory());
this.latencyHistoryWindow = fromLinkInfo.getLatencyHistoryWindow();
this.latencyUpdateThreshold = fromLinkInfo.getLatencyUpdateThreshold();
}
项目:fresco_floodlight
文件:LinkInfo.java
private U64 getLatencyHistoryAverage() {
if (!isLatencyHistoryFull()) {
return null;
} else { /* guaranteed to be at latencyHistoryWindow capacity */
double avg = 0;
for (U64 l : latencyHistory) {
avg = avg + l.getValue();
}
avg = avg / latencyHistoryWindow;
return U64.of((long) avg);
}
}
项目:fresco_floodlight
文件:LinkInfo.java
/**
* Append a new (presumably most recent) latency
* to the list. Sets the current latency if this
* is the first latency update performed. Note
* the latter serves as a latency initializer.
*
* @param latency
* @return latency to use for the link; either initial or historical average
*/
public U64 addObservedLatency(U64 latency) {
if (isLatencyHistoryFull()) {
latencyHistory.removeFirst();
}
latencyHistory.addLast(latency);
if (currentLatency == null) {
currentLatency = latency;
return currentLatency;
} else {
return getLatency();
}
}
项目:iTAP-controller
文件:LearningSwitch.java
/**
* Processes a flow removed message. We will delete the learned MAC/VLAN mapping from
* the switch's table.
* @param sw The switch that sent the flow removed message.
* @param flowRemovedMessage The flow removed message.
* @return Whether to continue processing this message or stop.
*/
private Command processFlowRemovedMessage(IOFSwitch sw, OFFlowRemoved flowRemovedMessage) {
if (!flowRemovedMessage.getCookie().equals(U64.of(LearningSwitch.LEARNING_SWITCH_COOKIE))) {
return Command.CONTINUE;
}
if (log.isTraceEnabled()) {
log.trace("{} flow entry removed {}", sw, flowRemovedMessage);
}
Match match = flowRemovedMessage.getMatch();
// When a flow entry expires, it means the device with the matching source
// MAC address and VLAN either stopped sending packets or moved to a different
// port. If the device moved, we can't know where it went until it sends
// another packet, allowing us to re-learn its port. Meanwhile we remove
// it from the macVlanToPortMap to revert to flooding packets to this device.
this.removeFromPortMap(sw, match.get(MatchField.ETH_SRC),
match.get(MatchField.VLAN_VID) == null
? VlanVid.ZERO
: match.get(MatchField.VLAN_VID).getVlanVid());
// Also, if packets keep coming from another device (e.g. from ping), the
// corresponding reverse flow entry will never expire on its own and will
// send the packets to the wrong port (the matching input port of the
// expired flow entry), so we must delete the reverse entry explicitly.
Match.Builder mb = sw.getOFFactory().buildMatch();
mb.setExact(MatchField.ETH_SRC, match.get(MatchField.ETH_DST))
.setExact(MatchField.ETH_DST, match.get(MatchField.ETH_SRC));
if (match.get(MatchField.VLAN_VID) != null) {
mb.setExact(MatchField.VLAN_VID, match.get(MatchField.VLAN_VID));
}
this.writeFlowMod(sw, OFFlowModCommand.DELETE, OFBufferId.NO_BUFFER, mb.build(), match.get(MatchField.IN_PORT));
return Command.CONTINUE;
}
项目:fresco_floodlight
文件:InstructionUtils.java
/**
* Convert an OFInstructionMetadata to string form. The string will be formatted
* in a dpctl/ofctl-style syntax.
* @param inst; The instruction to convert to a string
* @param log
* @return
*/
public static String writeMetadataToString(OFInstructionWriteMetadata inst, Logger log) {
/*
* U64.toString() formats with a leading 0x
*/
if (inst.getMetadataMask().equals(U64.NO_MASK)) { // don't give the mask if it's all 1's --> omit "/"
return inst.getMetadata().toString();
} else {
return inst.getMetadata().toString() + "/" + inst.getMetadataMask().toString();
}
}
项目:iTAP-controller
文件:VirtualNetworkFilter.java
/**
* Writes a FlowMod to a switch that inserts a drop flow.
* @param sw The switch to write the FlowMod to.
* @param pi The corresponding OFPacketIn. Used to create the OFMatch structure.
* @param cntx The FloodlightContext that gets passed to the switch.
*/
protected void doDropFlow(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
if (log.isTraceEnabled()) {
log.trace("doDropFlow pi={} srcSwitch={}",
new Object[] { pi, sw });
}
if (sw == null) {
log.warn("Switch is null, not installing drop flowmod for PacketIn {}", pi);
return;
}
// Create flow-mod based on packet-in and src-switch
OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowModify();
List<OFAction> actions = new ArrayList<OFAction>(); // no actions = drop
U64 cookie = AppCookie.makeCookie(APP_ID, 0);
fmb.setCookie(cookie)
.setIdleTimeout(ForwardingBase.FLOWMOD_DEFAULT_IDLE_TIMEOUT)
.setHardTimeout(ForwardingBase.FLOWMOD_DEFAULT_HARD_TIMEOUT)
.setBufferId(OFBufferId.NO_BUFFER)
.setMatch(pi.getMatch())
.setActions(actions);
if (log.isTraceEnabled()) {
log.trace("write drop flow-mod srcSwitch={} match={} " +
"pi={} flow-mod={}",
new Object[] {sw, pi.getMatch(), pi, fmb.build()});
}
sw.write(fmb.build());
return;
}
项目:fresco_floodlight
文件:TopologyManager.java
@Override
public ArrayList<Route> getRoutes(DatapathId srcDpid, DatapathId dstDpid,
boolean tunnelEnabled) {
// Floodlight supports single path routing now
// return single path now
ArrayList<Route> result=new ArrayList<Route>();
result.add(getRoute(srcDpid, dstDpid, U64.of(0), tunnelEnabled));
return result;
}
项目:fresco_floodlight
文件:SwitchPortBandwidth.java
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;
}
项目:iTAP-controller
文件:OFSwitchHandshakeHandler.java
@Override
void processOFNiciraControllerRoleRequest(OFNiciraControllerRoleRequest m) {
OFControllerRole role;
switch (m.getRole()) {
case ROLE_MASTER:
role = OFControllerRole.ROLE_MASTER;
break;
case ROLE_SLAVE:
role = OFControllerRole.ROLE_SLAVE;
break;
case ROLE_OTHER:
role = OFControllerRole.ROLE_EQUAL;
break;
default:
log.error("Attempted to change to invalid Nicira role {}.", m.getRole().toString());
return;
}
/*
* This will get converted back to the correct factory of the switch later.
* We will use OFRoleRequest though to simplify the API between OF versions.
*/
sendRoleRequest(OFFactories.getFactory(OFVersion.OF_13).buildRoleRequest()
.setGenerationId(U64.ZERO)
.setXid(m.getXid())
.setRole(role)
.build());
}
项目:iTAP-controller
文件:StaticFlowEntries.java
/**
* This function generates a random hash for the bottom half of the cookie
*
* @param fm
* @param userCookie
* @param name
* @return A cookie that encodes the application ID and a hash
*/
public static U64 computeEntryCookie(int userCookie, String name) {
// flow-specific hash is next 20 bits LOOK! who knows if this
int prime = 211;
int flowHash = 2311;
for (int i=0; i < name.length(); i++) {
flowHash = flowHash * prime + (int)name.charAt(i);
}
return AppCookie.makeCookie(StaticFlowEntryPusher.STATIC_FLOW_APP_ID, flowHash);
}
项目:fresco_floodlight
文件:LinkDiscoveryManagerTest.java
@Test
public void testLinkLatency() throws Exception {
LinkDiscoveryManager.LATENCY_HISTORY_SIZE = 5;
LinkDiscoveryManager.LATENCY_UPDATE_THRESHOLD = 0.25;
LinkInfo info = new LinkInfo(new Date(), new Date(), null);
/*
* Should retain initial latency until LATENCY_HISTORY_SIZE
* data points are accumulated.
*/
assertEquals(U64.of(0), info.addObservedLatency(U64.of(0)));
assertEquals(U64.of(0), info.addObservedLatency(U64.of(10)));
assertEquals(U64.of(0), info.addObservedLatency(U64.of(20)));
assertEquals(U64.of(0), info.addObservedLatency(U64.of(30)));
assertEquals(U64.of(20), info.addObservedLatency(U64.of(40)));
/*
* LATENCY_HISTORY_SIZE is maintained. Oldest value is evicted
* per new value added. New average should be computed each
* addition, but latency should not change until current latency
* versus historical average latency differential threshold is
* exceeded again.
*/
assertEquals(U64.of(20), info.addObservedLatency(U64.of(20))); /* avg = 24; diff = 4; 4/24 = 1/6 = 17% !>= 25% --> no update */
assertEquals(U64.of(26), info.addObservedLatency(U64.of(20))); /* avg = 26; diff = 6; 6/20 = 3/10 = 33% >= 25% --> update */
assertEquals(U64.of(26), info.addObservedLatency(U64.of(20))); /* avg = 26; diff = 0; 0/20 = 0/10 = 0% !>= 25% --> no update */
}
项目:fresco_floodlight
文件:TopologyManagerTest.java
@Test
public void testBasic1() throws Exception {
tm.addOrUpdateLink(DatapathId.of(1), OFPort.of(1), DatapathId.of(2), OFPort.of(1), U64.ZERO, ILinkDiscovery.LinkType.DIRECT_LINK);
assertTrue(tm.getSwitchPorts().size() == 2); // for two nodes.
assertTrue(tm.getSwitchPorts().get(DatapathId.of(1)).size()==1);
assertTrue(tm.getSwitchPorts().get(DatapathId.of(2)).size()==1);
assertTrue(tm.getSwitchPortLinks().size()==2);
assertTrue(tm.getPortBroadcastDomainLinks().size()==0);
assertTrue(tm.getTunnelPorts().size()==0);
tm.addOrUpdateLink(DatapathId.of(1), OFPort.of(2), DatapathId.of(2), OFPort.of(2), U64.ZERO, ILinkDiscovery.LinkType.MULTIHOP_LINK);
assertTrue(tm.getSwitchPorts().size() == 2); // for two nodes.
assertTrue(tm.getSwitchPorts().get(DatapathId.of(1)).size()==2);
assertTrue(tm.getSwitchPorts().get(DatapathId.of(2)).size()==2);
assertTrue(tm.getSwitchPortLinks().size()==4);
assertTrue(tm.getPortBroadcastDomainLinks().size()==2);
assertTrue(tm.getTunnelPorts().size()==0);
tm.removeLink(DatapathId.of(1), OFPort.of(2), DatapathId.of(2), OFPort.of(2));
assertTrue(tm.getSwitchPorts().get(DatapathId.of(1)).size()==1);
assertTrue(tm.getSwitchPorts().get(DatapathId.of(2)).size()==1);
assertTrue(tm.getSwitchPorts().size() == 2);
assertTrue(tm.getSwitchPortLinks().size()==2);
assertTrue(tm.getPortBroadcastDomainLinks().size()==0);
tm.removeLink(DatapathId.of(1), OFPort.of(1), DatapathId.of(2), OFPort.of(1));
assertTrue(tm.getSwitchPorts().size() == 0);
assertTrue(tm.getSwitchPortLinks().size()==0);
assertTrue(tm.getPortBroadcastDomainLinks().size()==0);
}
项目:fresco_floodlight
文件:OFSwitchHandshakeHandler.java
@Override
void processOFNiciraControllerRoleRequest(OFNiciraControllerRoleRequest m) {
OFControllerRole role;
switch (m.getRole()) {
case ROLE_MASTER:
role = OFControllerRole.ROLE_MASTER;
break;
case ROLE_SLAVE:
role = OFControllerRole.ROLE_SLAVE;
break;
case ROLE_OTHER:
role = OFControllerRole.ROLE_EQUAL;
break;
default:
log.error("Attempted to change to invalid Nicira role {}.", m.getRole().toString());
return;
}
/*
* This will get converted back to the correct factory of the switch later.
* We will use OFRoleRequest though to simplify the API between OF versions.
*/
sendRoleRequest(OFFactories.getFactory(OFVersion.OF_13).buildRoleRequest()
.setGenerationId(U64.ZERO)
.setXid(m.getXid())
.setRole(role)
.build());
}