tom

Merge remote-tracking branch 'origin/master'

1 +package org.onlab.onos.net.trivial.packet.impl;
2 +
3 +import static org.slf4j.LoggerFactory.getLogger;
4 +
5 +import org.onlab.onos.net.packet.PacketContext;
6 +import org.onlab.onos.net.packet.PacketProcessor;
7 +import org.slf4j.Logger;
8 +
9 +public class ReactivePacketProcessor implements PacketProcessor {
10 +
11 + private final Logger log = getLogger(getClass());
12 +
13 + @Override
14 + public void process(PacketContext context) {
15 + log.info("Packet reveived {}", context.inPacket());
16 + }
17 +
18 +}
1 +package org.onlab.onos.net.trivial.packet.impl;
2 +
3 +import static org.slf4j.LoggerFactory.getLogger;
4 +
5 +import java.util.ArrayList;
6 +
7 +import org.apache.felix.scr.annotations.Activate;
8 +import org.apache.felix.scr.annotations.Component;
9 +import org.apache.felix.scr.annotations.Deactivate;
10 +import org.apache.felix.scr.annotations.Reference;
11 +import org.apache.felix.scr.annotations.ReferenceCardinality;
12 +import org.apache.felix.scr.annotations.Service;
13 +import org.onlab.onos.net.Device;
14 +import org.onlab.onos.net.device.DeviceService;
15 +import org.onlab.onos.net.packet.OutboundPacket;
16 +import org.onlab.onos.net.packet.PacketContext;
17 +import org.onlab.onos.net.packet.PacketProcessor;
18 +import org.onlab.onos.net.packet.PacketProvider;
19 +import org.onlab.onos.net.packet.PacketProviderRegistry;
20 +import org.onlab.onos.net.packet.PacketProviderService;
21 +import org.onlab.onos.net.packet.PacketService;
22 +import org.onlab.onos.net.provider.AbstractProviderRegistry;
23 +import org.onlab.onos.net.provider.AbstractProviderService;
24 +import org.slf4j.Logger;
25 +
26 +
27 +/**
28 + * Provides a basic implementation of the packet SB & NB APIs.
29 + *
30 + */
31 +@Component(immediate = true)
32 +@Service
33 +public class SimplePacketManager
34 +extends AbstractProviderRegistry<PacketProvider, PacketProviderService>
35 +implements PacketService, PacketProviderRegistry {
36 +
37 + private final Logger log = getLogger(getClass());
38 +
39 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
40 + private DeviceService deviceService;
41 +
42 + private final ArrayList<PacketProcessor> processors = new ArrayList<>();
43 +
44 + private final PacketProcessor reactiveProcessor = new ReactivePacketProcessor();
45 +
46 + @Activate
47 + public void activate() {
48 + addProcessor(reactiveProcessor, PacketProcessor.ADVISOR_MAX + 1);
49 + log.info("Started");
50 + }
51 +
52 + @Deactivate
53 + public void deactivate() {
54 + removeProcessor(reactiveProcessor);
55 + log.info("Stopped");
56 + }
57 +
58 + @Override
59 + public void addProcessor(PacketProcessor processor, int priority) {
60 + processors.add(priority, processor);
61 + }
62 +
63 + @Override
64 + public void removeProcessor(PacketProcessor processor) {
65 + processors.remove(processor);
66 + }
67 +
68 + @Override
69 + public void emit(OutboundPacket packet) {
70 + final Device device = deviceService.getDevice(packet.sendThrough());
71 + final PacketProvider packetProvider = getProvider(device.providerId());
72 + packetProvider.emit(packet);
73 + }
74 +
75 + @Override
76 + protected PacketProviderService createProviderService(
77 + PacketProvider provider) {
78 + return new InternalPacketProviderService(provider);
79 + }
80 +
81 + // Personalized link provider service issued to the supplied provider.
82 + private class InternalPacketProviderService
83 + extends AbstractProviderService<PacketProvider>
84 + implements PacketProviderService {
85 +
86 + protected InternalPacketProviderService(PacketProvider provider) {
87 + super(provider);
88 + }
89 +
90 + @Override
91 + public void processPacket(PacketContext context) {
92 + for (PacketProcessor processor : processors) {
93 + processor.process(context);
94 + }
95 + }
96 +
97 + }
98 +}
...@@ -102,7 +102,7 @@ public class LinkDiscovery implements TimerTask { ...@@ -102,7 +102,7 @@ public class LinkDiscovery implements TimerTask {
102 this.sw = sw; 102 this.sw = sw;
103 this.ofFactory = sw.factory(); 103 this.ofFactory = sw.factory();
104 this.ctrl = ctrl; 104 this.ctrl = ctrl;
105 - this.probeRate = 1000; 105 + this.probeRate = 3000;
106 this.linkProvider = providerService; 106 this.linkProvider = providerService;
107 this.slowPorts = Collections.synchronizedSet(new HashSet<Integer>()); 107 this.slowPorts = Collections.synchronizedSet(new HashSet<Integer>());
108 this.fastPorts = Collections.synchronizedSet(new HashSet<Integer>()); 108 this.fastPorts = Collections.synchronizedSet(new HashSet<Integer>());
...@@ -129,7 +129,7 @@ public class LinkDiscovery implements TimerTask { ...@@ -129,7 +129,7 @@ public class LinkDiscovery implements TimerTask {
129 addPort(port); 129 addPort(port);
130 } 130 }
131 } 131 }
132 - timeout = Timer.getTimer().newTimeout(this, this.probeRate, 132 + timeout = Timer.getTimer().newTimeout(this, 0,
133 TimeUnit.MILLISECONDS); 133 TimeUnit.MILLISECONDS);
134 this.log.debug("Started discovery manager for switch {}", 134 this.log.debug("Started discovery manager for switch {}",
135 sw.getId()); 135 sw.getId());
......
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<project xmlns="http://maven.apache.org/POM/4.0.0"
3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5 + <modelVersion>4.0.0</modelVersion>
6 +
7 + <parent>
8 + <groupId>org.onlab.onos</groupId>
9 + <artifactId>onos-of-providers</artifactId>
10 + <version>1.0.0-SNAPSHOT</version>
11 + <relativePath>../pom.xml</relativePath>
12 + </parent>
13 +
14 + <artifactId>onos-of-provider-packet</artifactId>
15 + <packaging>bundle</packaging>
16 +
17 + <description>ONOS OpenFlow protocol packet provider</description>
18 +
19 +</project>
1 +package org.onlab.onos.provider.of.packet.impl;
2 +
3 +import static org.slf4j.LoggerFactory.getLogger;
4 +
5 +import org.apache.felix.scr.annotations.Activate;
6 +import org.apache.felix.scr.annotations.Component;
7 +import org.apache.felix.scr.annotations.Deactivate;
8 +import org.apache.felix.scr.annotations.Reference;
9 +import org.apache.felix.scr.annotations.ReferenceCardinality;
10 +import org.onlab.onos.net.packet.OutboundPacket;
11 +import org.onlab.onos.net.packet.PacketProvider;
12 +import org.onlab.onos.net.packet.PacketProviderRegistry;
13 +import org.onlab.onos.net.packet.PacketProviderService;
14 +import org.onlab.onos.net.provider.AbstractProvider;
15 +import org.onlab.onos.net.provider.ProviderId;
16 +import org.onlab.onos.of.controller.OpenFlowController;
17 +import org.onlab.onos.of.controller.OpenFlowPacketContext;
18 +import org.onlab.onos.of.controller.PacketListener;
19 +import org.slf4j.Logger;
20 +
21 +/**
22 + * Provider which uses an OpenFlow controller to detect network
23 + * infrastructure links.
24 + */
25 +@Component(immediate = true)
26 +public class OpenFlowPacketProvider extends AbstractProvider implements PacketProvider {
27 +
28 + private final Logger log = getLogger(getClass());
29 +
30 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
31 + protected PacketProviderRegistry providerRegistry;
32 +
33 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
34 + protected OpenFlowController controller;
35 +
36 + private PacketProviderService providerService;
37 +
38 + private final boolean useBDDP = true;
39 +
40 + private final InternalPacketProvider listener = new InternalPacketProvider();
41 +
42 +
43 +
44 + /**
45 + * Creates an OpenFlow link provider.
46 + */
47 + public OpenFlowPacketProvider() {
48 + super(new ProviderId("org.onlab.onos.provider.openflow"));
49 + }
50 +
51 + @Activate
52 + public void activate() {
53 + providerService = providerRegistry.register(this);
54 + controller.addPacketListener(0, listener);
55 + log.info("Started");
56 + }
57 +
58 + @Deactivate
59 + public void deactivate() {
60 + providerRegistry.unregister(this);
61 + controller.removePacketListener(listener);
62 + providerService = null;
63 + log.info("Stopped");
64 + }
65 +
66 + @Override
67 + public void emit(OutboundPacket packet) {
68 + // TODO Auto-generated method stub
69 +
70 + }
71 +
72 +
73 + private class InternalPacketProvider implements PacketListener {
74 +
75 +
76 + @Override
77 + public void handlePacket(OpenFlowPacketContext pktCtx) {
78 +
79 +
80 + }
81 +
82 + }
83 +
84 +
85 +}
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
20 <module>device</module> 20 <module>device</module>
21 <module>link</module> 21 <module>link</module>
22 <module>host</module> 22 <module>host</module>
23 + <module>packet</module>
23 </modules> 24 </modules>
24 25
25 <dependencies> 26 <dependencies>
......